Computing.Net > Forums > Unix > Change last line of file using sed

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.

Change last line of file using sed

Reply to Message Icon

Name: shamim.tcs
Date: November 1, 2006 at 23:33:03 Pacific
OS: AIX 5.3
CPU/Ram: Intel , 552 MB
Product: IBM
Comment:

Hi,

I wish to add "\" symbol at the end of each line of a file, except the last one.
e.g.

Original file:

(OBJ)/a.o
(OBJ)/b.o
(OBJ)/c.o
(OBJ)/d.o

Desired ouput:

(OBJ)/a.o \
(OBJ)/b.o \
(OBJ)/c.o \
(OBJ)/d.o

Asst. Systems Engineer
Tata Consultancy Services



Sponsored Link
Ads by Google

Response Number 1
Name: Devaraj (by Fidy)
Date: November 2, 2006 at 03:13:57 Pacific
Reply:

You can use "sed" to do the Job.
Try this

sed '$q;s/$/\//g' inputfile > outputfile

This will produce the output as

(OBJ)/a.o /
(OBJ)/b.o /
(OBJ)/c.o /
(OBJ)/d.o

-Devaraj Takhellambam

Regards,
Devaraj Takhellambam


0

Response Number 2
Name: Devaraj (by Fidy)
Date: November 2, 2006 at 03:30:20 Pacific
Reply:

sorry , use

sed '$q;s/$/\\/g' sedfile.

I had mistaken for a "\" with a "/".

Regards,
Devaraj Takhellambam


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: Change last line of file using sed

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

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

Last line of a file www.computing.net/answers/unix/last-line-of-a-file/5489.html