有文件file,内容为1234567898453613025(n个数字),编写程序实现每隔4个数字就换行。脚本编写如下:
${string::N}提取前N个字符,${string:N}提取N个之后的字符
# cat ./test.sh
#!/bin/bash test=1234567898453613025 num_test=`echo ${#test}` num=$[num_test/4 + 1 ] for i in `seq $num` do echo -ne "${test::4}" test=`echo ${test:4}` echo done# ./test.sh
1234
5678
9845
3613
025
#