Register
It is currently Sat Nov 01, 2014 4:27 am

script to delete rows from a given "line number"


All times are UTC - 6 hours


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 PostPosted: Fri May 14, 2010 2:34 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hi eveyrone

I need to create a script that deletes rows from a given csv file at a given position.
So for example:

my file.csv has 5000 rows..
0 ..

1024 ..
1025 ..

5000.

but I only want 0 to 1024. Anyone know how I can do this?

Ed.


Top
 Profile  
 PostPosted: Fri May 14, 2010 2:59 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
Code:
sed -n '1,1024p' < input.file >>output.file


Top
 Profile WWW  
 PostPosted: Fri May 14, 2010 5:11 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
crouse wrote:
Code:
sed -n '1,1024p' < input.file >>output.file

Or, shorter:
Code:
sed '1,1024!d' input.file >> output.file
:-B


Top
 Profile  
 PostPosted: Fri May 14, 2010 5:46 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Thanks so much :)


Top
 Profile  
 PostPosted: Tue May 18, 2010 9:24 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hey everyone,

How do I make the 1024 to a variable I can get from a bash script?

sed -n '1,1024p' < input.file >>output.file

Ted.


Top
 Profile  
 PostPosted: Tue May 18, 2010 4:41 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
Code:
count=1024
sed -n 1,"$count"p < input.file >>output.file

:-/ I noticed you numbered lines from 0. In such a case, you have to use 1025 as the value!


Top
 Profile  
 PostPosted: Wed May 19, 2010 4:19 am   

Joined: Tue May 18, 2010 7:08 am
Posts: 5
head -1025 input _file >> out_file


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP