Our application installation uses "sed" command to append string after specific line or after line number.
Both cases work perfect on Linux but fail on Solaris.
The OS versions are Solaris 9 and Linux Red Hat AS 3.
i.g:
Linux:
-----
file foo.txt
aaa
bbb
ccc
ddd
root# uname -s
Linux
root# sed '2a\Add this line after line 2\' foo.txt
aaa
bbb
Add this line after line 2
ccc
ddd
root# sed '/bbb/ a\Add this line after bbb' foo.txt
aaa
bbb
Add this line after bbb
ccc
ddd
Sun Solaris
-----------
root# uname -s
SunOS
root# sed '/bbb/ a\Add this line after bbb' foo.txt
sed: command garbled: /bbb/ a\Add this line after bbb
root# sed '2a\Add this line after line 2\' foo.txt
aaa
bbb
ccc
ddd
As you can see,sed works fine on Linux but not on Solaris.
Is there a different in sed syntax between platforms?
root# sed '2a\Add this line after line 2' foo.txt
sed: command garbled: 2a\Add this line after line 2
root# sed '2a\^JAdd this line after line 2' foo.txt
sed: command garbled: 2a\^JAdd this line after line 2
For the first solution don't forget the newline after 2a\.
\ MUST be the last character of the line.
The second part of the command must be in a second line.
root# sed '2a\
Add this line after line 2' foo.txt