${string::N}和${string:N}字符提取
有文件file,内容为1234567898453613025(n个数字),编写程序实现每隔4个数字就换行。脚本编写如下: ${string::N}提取前N个字符,${string:N}提取N个之后的字符 。
1# cat ./test.sh
2#!/bin/bash
3test=1234567898453613025
4num_test=`echo ${#test}`
5num=$[num_test/4 + 1 ]
6for i in `seq $num`
7do
8 echo -ne "${test::4}"
9 test=`echo ${test:4}`
10 echo
11done
执行后的结果是:
1# ./test.sh
21234
35678
49845
53613
6025
7#
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/character-extraction/2834.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.