Computing.Net > Forums > Unix > Sed script trimming last line

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

Reply to Message Icon

Original Message
Name: guruprasadv
Date: March 22, 2005 at 18:11:54 Pacific
Subject: Sed script trimming last line
OS: Solaris
CPU/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 1
Name: gurubit
Date: March 23, 2005 at 03:21:19 Pacific
Reply: (edit)

It works fine for me.
Put the contents file that you are using and also the $1 and the $2 options.


Report Offensive Follow Up 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








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge
Poll History




Data Recovery Software