Command to insert lines before first match

前端 未结 3 1287
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 05:46

I have file with the below info

testing
testing
testing

I want to insert a word(tested) before the first testing word using sed or any linu

3条回答
  •  时光取名叫无心
    2021-01-05 06:08

    This might work for you (GNU sed):

    sed -e '/testing/{itested' -e ':a;n;ba}' file
    

    Insert tested before the first match of testing and then use a loop to read/print the remainder of the file.

    Or use the GNU specific:

    sed '0,/testing/itested' file
    

提交回复
热议问题