sed: insert a string after every N lines

前端 未结 6 2046
無奈伤痛
無奈伤痛 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:11

    This thread is another example of how to over complicate things. This should do it:

    sed '0~30 s/$/string/g' < inputfile > outputfile
    

    Every 30 lines "string" is inserted at the end of the line. If you want a new line with the word "string" just use "\n string".

提交回复
热议问题