Unix/Linux Go Back    



best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

UNIX for Dummies Questions & Answers




Kindly Note - This is a Single User Post by Forum Member Scott Regarding:
best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :).
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 08-26-2010
Scott's Unix or Linux Image
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 22 October 2017, 4:23 AM EDT
Location: Zürich
Posts: 8,750
Thanks: 356
Thanked 1,161 Times in 995 Posts
Linux

I just tried on Solaris 10. If the last line has no new line, it deletes the line.

OSX:

Code:
$ printf "1\n2\n3\n4" > file1
$ sed "s/3/33/" file1
1
2
33
4

Solaris:

Code:
# printf "1\n2\n3\n4" > file1
# sed "s/3/33/" file1
1
2
33

# echo >> file1
# sed "s/3/33/" file1
1
2
33
4

You mentioned OpenSolaris in an earlier post - I missed that

Interestingly (or not Linux), using ed:


Code:
# ed file1 << !
> 1,$ s/3/33/
> w
> q
> !
'\n' appended
8
9
# cat file1
1
2
33
4


Last edited by Scott; 08-26-2010 at 12:31 PM..