The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed remove last 10 characters of a line start from 3rd line minifish Shell Programming and Scripting 7 03-26-2008 01:42 PM
SED help (remove line::parse again::add line) Malumake Shell Programming and Scripting 6 10-24-2007 02:02 PM
remove line 1 and save it.... happyv Shell Programming and Scripting 10 12-19-2006 11:32 PM
Remove header(first line) and trailer(last line) in ANY given file madhunk Shell Programming and Scripting 2 03-13-2006 12:36 PM
To remove new line character shihabvk UNIX for Advanced & Expert Users 6 08-18-2005 12:02 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 01-27-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Remove first 15 line

Friends,

I have a file with 1000 lines. How can I remove the first 15 lines and 20 lines from BOTTOM of the file UP.

Many thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 01-27-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Code:
sed -n -e '16,980p' file
Reply With Quote
  #3  
Old 01-27-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Thank you Vino

What about 20 lines from bottom up. And the files' line-number are randomly come in. sometimes, 850, 900, 700 ....
Reply With Quote
  #4  
Old 01-27-2006
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
wc -l filename | awk '{ printf "%d",$1-20'} | xargs -I {} head -{} filename

or

sed -n "1,$(($(wc -l file1 | awk '{print $1'})-20)) p" filename

try the second one in ksh
Reply With Quote
  #5  
Old 01-28-2006
Registered User
 

Join Date: Dec 2005
Location: India
Posts: 218
try the following

ex file_name
:1,5d (specify the range of lines to delete)
:wq!

specify the range correctly to delete the lines.

cheers,
Gaurav
Reply With Quote
  #6  
Old 01-28-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,609
Code:
lines=$((`sed -n '$=' samplefile` - 20)); awk '{ if(NR > 15 && NR < '$lines') print}' samplefile
Reply With Quote
  #7  
Old 01-30-2006
Registered User
 

Join Date: Jan 2006
Posts: 145
Thank you much!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:24 AM.


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