The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > AIX
Google UNIX.COM


AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing the first and last lines in a file naveendronavall Shell Programming and Scripting 2 12-29-2007 10:22 PM
Removing lines from a file computersaysno UNIX for Dummies Questions & Answers 6 11-14-2006 03:50 PM
Removing lines within a file tookers Shell Programming and Scripting 3 08-22-2006 06:49 AM
Removing lines from a file PradeepRed Shell Programming and Scripting 4 12-17-2005 03:34 AM
Removing lines in a text file. WABonnett Shell Programming and Scripting 4 11-25-2003 08:27 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-29-2007
Registered User
 

Join Date: Dec 2007
Posts: 3
Removing the first and last lines in a file

Hi Gurus,

I'm a little new to UNIX. How can I do remove the first and last line in a file? Say, supppose I have a file as below:

Code:
1DMA                 
400002BARRIE         
401002CALGARY/LETHBRI
402002CARLETON       
500001PORTLAND-AUBRN 
501001NEW YORK, NY   
502001BINGHAMTON, NY 
9DMA     255
I want to remove the line 1 and line 8 ( one which starts with '1DMA' meaning it is a header and the trailer which starts with '9DMA'). My final result should be as below:

Code:
400002BARRIE         
401002CALGARY/LETHBRI
402002CARLETON       
500001PORTLAND-AUBRN 
501001NEW YORK, NY   
502001BINGHAMTON, NY
Your help and inputs are greatly appreciated!

Many thanks,
Naveen.
Reply With Quote
Forum Sponsor
  #2  
Old 12-29-2007
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Here is one way:

Code:
sed -e '2,$!d' -e '$d' file
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:00 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0