| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
Sed script trimming last line
|
Original Message
|
Name: guruprasadv
Date: March 22, 2005 at 18:11:54 Pacific
Subject: Sed script trimming last lineOS: SolarisCPU/Ram: 512 |
Comment: Hi, I am going a global replace using the below script.My problem is the last line of the property file is getting deleted.Please any idea on this issue find /export/home/direfor -type f -name '*.properties' -print | while read i do echo "the files that are being read are: " $i sed 's|'$1'|'$2'|g' $i > $i.tmp && mv $i.tmp $i done Thanks Prasad.V
Report Offensive Message For Removal
|
|
Response Number 2
|
Name: Jim Boothe
Date: March 23, 2005 at 07:27:55 Pacific
|
Reply: (edit)sed will completely ignore the last line of the file if it is does not end with a newline. If this is the case, if you open one of these files with vi, it will issue a warning to this effect. awk does not ignore these incomplete last lines, so you could use: awk '{gsub("'$1'","'$2'");print}' $i > $i.tmp && mv $i.tmp $i
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Unix Forum Home