Appending line with sed works on Linux but not on Solaris


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Appending line with sed works on Linux but not on Solaris
# 1  
Old 08-10-2005
Appending line with sed works on Linux but not on Solaris

Hi folks,

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
Code:
aaa
bbb
ccc
ddd

Code:
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

Code:
root# sed '/bbb/ a\Add this line after bbb' foo.txt
aaa
bbb
Add this line after bbb
ccc
ddd

Sun Solaris
-----------
Code:
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

Code:
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?

Thanks in advance,
Nir
# 2  
Old 08-10-2005
The problem is the same for AIX
You must have a new line after the \
Code:
sed '2a\
Add this line after line 2' foo.txt

or

sed '2a\^JAdd this line after line 2' foo.txt

^J is inserted with ^V+^J
# 3  
Old 08-11-2005
Hi aigles,

Thanks for your reply.
Both suggestions failed:

Code:
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

Any other suggestions?

Thanks in advance,
Nir
# 4  
Old 08-11-2005
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
# 5  
Old 08-11-2005
Hi aigles,

Thanks a lot!!
It's working now perfect!!

Beset regards,
Nir
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed works on Linux but fails on Solaris

Hi, On Linux i get the desired ouput: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: Executing the same command on Solaris: echo "<value>WEB_USER</value>" | sed 's/\(<value>\|<\/value>\)//g'Output: I need to get the desired output on Solaris i.e. WEB_USER and... (4 Replies)
Discussion started by: mohtashims
4 Replies

2. Shell Programming and Scripting

Script works with Linux not with Solaris

Hi I have the following script which works in Linux shell but gives issues with Sun OS Solaris 5.10, What i am trying to achieve here is we have a list of file names in list.txt file and we parse each file at a time for a particular pattern and copt next 4 lines after we hit the pattern to a... (6 Replies)
Discussion started by: Yugendra
6 Replies

3. Shell Programming and Scripting

sed works on Linux and Unix does not work

Hi, I use this command in Linux but if I run the same command does not work in freebsd. Follow the below command: Linux works: sed -e '1731a\' -e '####' squid.conf > squid2.conf ; sed -e '1731a\' -e 'acl TESTE_ip src 192.168.1.1/255.255.255.255' squid2.conf > squid.conf ; sed -e... (7 Replies)
Discussion started by: andreirp
7 Replies

4. Shell Programming and Scripting

Delete rest of line with sed works on Linux but not on Solaris

Hi all, Our application installation uses "sed" command to delete rest of line. It work perfect on Linux but fail on Solaris. The OS versions are Solaris 9 and Linux Red Hat AS 3. yourfile.txt hello and world cat and dog hello world in linux: cat yourfile.txt | sed ‘s/\(\+\)... (3 Replies)
Discussion started by: javac2005
3 Replies

5. Shell Programming and Scripting

awk;sed appending line to previous line....

I know this has been asked before but I just can't parse the syntax as explained. I have a set of files that has user information spread out over two lines that I wish to merge into one: User1NameLast User1NameFirst User1Address E-Mail:User1email User2NameLast User2NameFirst User2Address... (11 Replies)
Discussion started by: walkerwheeler
11 Replies

6. Shell Programming and Scripting

sed: appending alternate line after previous line

Hi all, I have to append every alternate line after its previous line. For example if my file has following contents line 1: unix is an OS line 2: it is open source line 3: it supports shell programming line 4: we can write shell scripts Required output should be line1: unix is an OS it is... (4 Replies)
Discussion started by: rish_max
4 Replies

7. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (1 Reply)
Discussion started by: Silverhood
1 Replies

8. Shell Programming and Scripting

Script works on Solaris, not on Linux

I'm in the same boat as Barbus - same exercis (https://www.unix.com/shell-programming-scripting/43609-processes-users.html) The following script works on a solaris server I have access to. It doesn't however, work on the companies Linux machine. Any idea what's up? I have very little shell... (0 Replies)
Discussion started by: Silverhood
0 Replies

9. Shell Programming and Scripting

Sed - Appending a line with a variable on it

Hi, I searched the forum for this but couldn't find the answer. Basically I have a line of code I want to insert into a file using sed. The line of code is basically something like "address=1.1.1.1" where 1.1.1.1 is an IP Address that will vary depending on what the user enters. I'll just refer... (4 Replies)
Discussion started by: eltinator
4 Replies

10. Shell Programming and Scripting

Appending line/lines with sed

Hi folks, I need to append line or bulk of lines into a file. For example,I have the following section in opmn.xml file: <process-type id="OC4J_RTEadmin_NIR" module-id="OC4J"> <module-data> <category id="start-parameters"> <data... (28 Replies)
Discussion started by: nir_s
28 Replies
Login or Register to Ask a Question