Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 07-15-2004, 05:07 PM   #1
LQ Newbie
Registered: Dec 2003
Distribution: FreeBSD / Redhat
Posts: 9

Rep: Reputation: 0
CLI based Text manipulation

I am looking for a one liner that would delete
the last line of a text file, and remove the "#"
char from what is now the "new" last line under
RH9.0 / tcsh





Old 07-15-2004, 08:11 PM   #2
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
Using the 'wc' command you could get the number of lines in the file and use that number to select the range for sed, or ex.

If you use the 'ex' command, you could A) position to the last line B) delete the line C) use the command 's/^#\(.*\)/\1/'
on the new last line to delete the initial # character.
This method doesn't require using the 'wc' command so the file is read through only once, and using a line editor you don't need to redirect the output to a temporary file.


Actually since ex starts with the last line being the current line, you only need the latter steps I mentioned earlier.

ex - iplistfile <exscript

I'm not at all familiar with the tcsh, but a 'here' document may be possible to keep the exscript in the same script rather than in a separate file.

Last edited by jschiwal; 07-15-2004 at 09:20 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
truncate a text file in CLI? hottdogg Linux - General 2 09-06-2005 10:32 PM
Manipulation of text files in C++ Hady Programming 5 05-31-2005 09:24 AM
More text manipulation ice_hockey Linux - General 2 05-28-2005 02:43 AM
Recieve web-based email in CLI? PhoenixofMT Linux - Software 1 10-21-2004 04:22 PM
text color in the CLI hrc Linux - Software 7 06-25-2003 10:35 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:58 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration