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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sed script trimming last line

Reply to Message Icon

Name: guruprasadv
Date: March 22, 2005 at 18:11:54 Pacific
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




Sponsored Link
Ads by Google

Response Number 1
Name: gurubit
Date: March 23, 2005 at 03:21:19 Pacific
Reply:

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


0

Response Number 2
Name: Jim Boothe
Date: March 23, 2005 at 07:27:55 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: Sed script trimming last line

sed dropping last line of file www.computing.net/answers/unix/sed-dropping-last-line-of-file/5125.html

need help on SED script www.computing.net/answers/unix/need-help-on-sed-script/7487.html

Append to last line of file www.computing.net/answers/unix/append-to-last-line-of-file/5212.html