sed: insert a string after every N lines

前端 未结 6 2106
無奈伤痛
無奈伤痛 2021-01-31 03:55

I want to insert a string after every 30 lines in my large file. I\'m using mini-sed, which doesn\'t support ~ (tilde) range operator. I\'m looking for sed-only solution please.

6条回答
  •  我在风中等你
    2021-01-31 04:28

    This inserts a line every 3 lines;

    seq 1 10 | sed ': loop; n; n; a insert
    n; b loop'
    

    Producing

    1
    2
    3
    insert
    4
    5
    6
    insert
    7
    8
    9
    insert
    10
    

    adjust the number of n; commands before the a command accordingly

提交回复
热议问题