Substitution on range of lines

后端 未结 4 2029
独厮守ぢ
独厮守ぢ 2021-01-26 16:58

I have in 3rd line of a file. I want to replace that with my_dB. How to do this with sed

4条回答
  •  无人共我
    2021-01-26 17:31

    Like this:

    $ sed '3,6 s//my_dB/' file
    

    Demo:

    $ cat file
    1: 
    2: 
    3: 
    4: 
    5: 
    6: 
    7: 
    
    $ sed '3,6 s//my_dB/' file
    1: 
    2: 
    3: my_dB
    4: my_dB
    5: my_dB
    6: my_dB
    

        7:

    To store the changes back to the file use the -i option

    $ sed -i '3,6 s//my_bd/' file
    

    However you really should be using a XML parser. Getting into parsing XML with regexp is really a bad idea.

提交回复
热议问题