sed:每N行后插入一个字符串 [英] sed: insert a string after every N lines
本文介绍了sed:每N行后插入一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的大文件中每 30 行后插入一个字符串.我正在使用 mini-sed,它不支持 ~(波浪号)范围运算符.我正在寻找仅限 sed 的解决方案.
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.
推荐答案
这个线程是另一个如何将事情复杂化的例子.应该这样做:
This thread is another example of how to over complicate things. This should do it:
sed '0~30 s/$/string/g' < inputfile > outputfile
每 30 行字符串"在行尾插入.如果你想要一个带有 "string" 一词的新行,只需使用 "\n string".
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".
这篇关于sed:每N行后插入一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文