The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script works on Solaris, not on Linux Silverhood Shell Programming and Scripting 1 10-05-2007 10:52 AM
Script works on Solaris, not on Linux Silverhood Shell Programming and Scripting 0 10-05-2007 10:27 AM
Appending line ending with '}" to new line aismann Shell Programming and Scripting 4 08-13-2007 03:09 AM
Appending the line number and a seperator to each line of a file ? pjcwhite Shell Programming and Scripting 4 03-21-2007 01:29 AM
works from cmd-line but not in script OFFSIHR Shell Programming and Scripting 4 10-18-2006 09:41 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-10-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
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 (permalink)  
Old 08-10-2005
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
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 (permalink)  
Old 08-11-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
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 (permalink)  
Old 08-11-2005
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
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 (permalink)  
Old 08-11-2005
nir_s nir_s is offline
Registered User
  
 

Join Date: Jun 2004
Posts: 148
Hi aigles,

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

Beset regards,
Nir
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0