Computing.Net > Forums > Unix > Last line of a file

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.

Last line of a file

Reply to Message Icon

Name: Brian
Date: August 22, 2003 at 13:59:46 Pacific
OS: UNIX
CPU/Ram: LOTS
Comment:

Hello,
Recently began writing some UNIX scripts with a lot of success. One problem I have encountered that really stumps me. In an alias file, after I have removed all the users identified in another file I need to ensure that every line has a comma ( I have this part) EXCEPT the very last line. I need to know how to remove something only from the last line of test!!

Any help will be greatly appreciated.

Brian




Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: August 22, 2003 at 14:55:05 Pacific
Reply:

sed can target certain lines, then make substitutions just on those lines. For example, for each line that contains xyz, change each occurrence of foo to bar:

sed '/xyz/s/foo/bar/g' myfile

Or it can target a specific line. In the following, the last line only is targeted to change a comma at the end of the line to null:

sed '$s/,$//' myfile


0
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: Last line of a file

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

Delete first line of a file www.computing.net/answers/unix/delete-first-line-of-a-file/7594.html

Printing last few pages (or lines) of a www.computing.net/answers/unix/printing-last-few-pages-or-lines-of-a-/2268.html