LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 04-24-2009, 05:10 PM   #1
Mike_V
Member
 
Registered: Apr 2009
Location: Boston MA
Distribution: CentOS 4.6 x86_64 GNU/Linux
Posts: 34
Thanked: 0
Print only specific rows in a text file


[Log in to get rid of this advertisement]
Hi there,
thanks for your help with my questions yesterday!

I have a simple one now, I guess. Yet, getting a solution through Google with key words such as "awk, print, rows" seemed hard.


Here is my question:

I have a text file with 100 rows. I want to make "new_file1.txt" containing rows 1-10, "newfile_2.txt" containing rows 11-20, etc.

(By the way, each row contains a long string of characters, so there's not a clear column structure)

Thanks in advance,

Cheers,
Mike

Last edited by Mike_V; 04-24-2009 at 05:25 PM..
Mike_V is offline  
Tag This Post , ,
Reply With Quote
Old 04-24-2009, 06:07 PM   #2
paulsm4
Senior Member
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 3,318
Thanked: 144
Hi -

To print lines 1 through 10 (for example):
Quote:
sed '1,10!d' INFILE > OUTFILE
'Hope that helps .. PSM

PS:
Here's a great sed "cheat sheet":
http://student.northpark.edu/pemente/sed/sed1line.txt
paulsm4 is offline     Reply With Quote
Thanked by:
Old 04-24-2009, 06:33 PM   #3
ntubski
Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 698
Thanked: 50
The split program is written for exactly this task:
Code:
split --lines=10 --numeric-suffixes oldfile.txt newfile_

# if you want .txt extension
for f in newfile_* ; do
    mv $f $f.txt
done
ntubski is offline     Reply With Quote
Thanked by:
Old 04-24-2009, 08:18 PM   #4
Mike_V
Member
 
Registered: Apr 2009
Location: Boston MA
Distribution: CentOS 4.6 x86_64 GNU/Linux
Posts: 34
Thanked: 0

Original Poster
You guys are awesome!
Mike_V is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare two fields on consecutive rows and print the two rows aditi_borkar Linux - Newbie 3 04-09-2009 06:49 AM
How to print data in rows and columns suran Linux - General 3 03-15-2009 03:53 PM
deleting 100 rows in text file (1-100) via terminal itz2000 Linux - Newbie 5 01-18-2006 12:19 AM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 05:32 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 08:15 PM


All times are GMT -5. The time now is 10:21 PM.

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