linux shell实现将指定行重复指定的次数

1、测试数据

root@ubuntu01:/home/test2# cat test.txt   ## 实现将每一行按照第二行数字指定的行数重复
1       3       e3rt    idf
2       2       32      ffj
3       5       cc      kkk
4       4       wf      34

 

 

2、while + for循环实现

root@ubuntu01:/home/test2# cat test.txt
1       3       e3rt    idf
2       2       32      ffj
3       5       cc      kkk
4       4       wf      34
root@ubuntu01:/home/test2# cat test.txt | while read {i,j,k}; do for m in $(seq $j); do sed -n "$i"p test.txt >> restlt.txt; done; done
root@ubuntu01:/home/test2# ls
restlt.txt  test.txt
root@ubuntu01:/home/test2# cat restlt.txt   ## 第一行重复3次,第二行重复2次,第三行重复5次。。。。
1       3       e3rt    idf
1       3       e3rt    idf
1       3       e3rt    idf
2       2       32      ffj
2       2       32      ffj
3       5       cc      kkk
3       5       cc      kkk
3       5       cc      kkk
3       5       cc      kkk
3       5       cc      kkk
4       4       wf      34
4       4       wf      34
4       4       wf      34
4       4       wf      34

 

相关文章

Centos系统之Shell编程基础知识
从Export理解Shell环境和变量生存期
linux shell数组变量、类型及规则
Centos编程Shell基本工作原理方案
Centos操作系统编程之Shell 问答录
rsync-linux备份脚本