sed use to replace string 2 lines after matching pattern in AIX 6.1

6,634

AIX sed needs each command on a separate line. See man page and try

sed '/some_pattern/{
 N
 N
 s/word1/word2/
}'
Share:
6,634

Related videos on Youtube

JavaRed
Author by

JavaRed

I try to expertise on Java and some Unix power tools such as sed, awk as well as regex.

Updated on September 18, 2022

Comments

  • JavaRed
    JavaRed over 1 year

    I try to replace a character, 2 lines after matching pattern. For this, I'm using this code:

    sed '/some_pattern/{N;N;s/word1/word2/}' /etc/filesystems > /etc/filesystems.tmp && mv -f /etc/filesystems.tmp /etc/filesystems
    

    I tested this command and confirmed it's working fine on Linux. However, when I use it in AIX, I receive an error message like:

    sed: Function /some_pattern/{N;N;s/word1/word2/} cannot be parsed.
    

    Any idea?

  • Kusalananda
    Kusalananda almost 8 years
    Of course it does, since you're using GNU sed. GNU sed is not available on AIX unless it's installed separately.