在文本文件中,我希望在使用perl的另一行文本的每個匹配之前插入一行新文本。在文本匹配之前插入一行新文本
例子 - 我的文件是:
holiday
april
icecream: sunday
jujubee
carefree
icecream: sunday
Christmas
icecream: sunday
towel
...
我想插入一行文字'icecream: saturday'
的「icecream: sunday'
行之前。所以之後,文本文件看起來像。是的,我在搜索和替換模式中都需要冒號:
。
holiday
april
icecream: saturday
icecream: sunday
jujubee
carefree
icecream: saturday
icecream: sunday
Christmas
icecream: saturday
icecream: sunday
towel
...
我想在Windows PC上使用perl 5.14來做到這一點。我已經安裝了Perl。我在這個網站上搜索並嘗試了許多其他的例子,但他們不適合我,很不幸,我不是一個完整的Perl專家。
我也有Cygwin sed,如果有一個例子也使用sed。
向我們展示您的嘗試。 – mob