The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing last character from each line of file cjhancock Shell Programming and Scripting 17 08-29-2008 05:05 AM
Removing text from a line in a file outthere_3 Shell Programming and Scripting 10 02-13-2008 03:38 AM
removing a character and addending to end in each line in a file arunkumar_mca UNIX for Dummies Questions & Answers 5 01-30-2008 12:48 AM
Removing a particular line from a text file sendhilmani123 Shell Programming and Scripting 5 05-31-2006 09:32 AM
perl question - removing line from input file reggiej Shell Programming and Scripting 3 06-07-2005 02:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-19-2008
akeenabawa akeenabawa is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 8
Exclamation Removing last line from file

Hi, I searched the forums but could not find anything that was very useful. I am trying to remove the very last line from a file and display the rest of the file.
Is there a way to use cut and tail together? Any other suggestions? Thanks
  #2 (permalink)  
Old 08-19-2008
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
sed '$d' <input_filename >output_filename
  #3 (permalink)  
Old 08-19-2008
akeenabawa akeenabawa is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 8
Do you have to make an output file?
  #4 (permalink)  
Old 08-19-2008
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
Thumbs up

what do you want???

1. to just display

$ sed '$d' your_infile_name

2. to save the changes to a new file

$ sed '$d' <your_input_filename >new_output_filename

were the new_output_filename will be created once the command got executed. instead of your_input_filename provide your source filename and instead of output_filename just give some name. once after executed a new file will be created without the last line from your input_filename.
  #5 (permalink)  
Old 08-19-2008
sudhamacs sudhamacs is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 98
If you do not want to create extra file then you can do this :

echo "`sed '$d' file`" > file
  #6 (permalink)  
Old 08-19-2008
akeenabawa akeenabawa is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 8
I ran that command

Code:
sed '$d' OLD_FILE > NEW_FILE

and it just displays the OLD_FILE contents.
In other words I want to display everything up to the last line of the OLD_FILE but I don't know how many lines there are in the file, it changes everyday.
  #7 (permalink)  
Old 08-19-2008
palsevlohit_123 palsevlohit_123 is offline
Registered User
  
 

Join Date: Aug 2008
Location: India-Chennai
Posts: 120
Talking

that's ok,

can you check the old and the new files.

old file will contain all the lines.
new file will contain 1 line minus than the old.

So, your correct output will be in NEW_FILE.

Note: no issue with the no of line in the files.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0