find matching text and replace next line

前端 未结 3 1519
北恋
北恋 2020-12-02 22:01

I\'m trying to find a line in a file and replace the next line with a specific value. I tried sed, but it seems to not like the \\n. How else can this be done?

The f

3条回答
  •  抹茶落季
    2020-12-02 22:43

    One way: Sample file

    $ cat file
    Cygwin
    Unix
    Linux
    Solaris
    AIX
    

    Using sed, replacing the next line after the pattern 'Unix' with 'hi':

    $ sed '/Unix/{n;s/.*/hi/}' file
    Cygwin
    Unix
    hi
    Solaris
    AIX
    

    For your specific question:

    $ sed '/ConnectionString<\/key>/{n;s/.*<\/string>/NEW STRING<\/string>/}' your_file
    ConnectionString
    NEW STRING
    

提交回复
热议问题