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
原文地址:https://www.cnblogs.com/liujiaxin2018/p/15677580.html