LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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

Reply
 
Search this Thread
Old 04-24-2009, 04:10 PM   #1
Mike_V
Member
 
Registered: Apr 2009
Location: Boston MA
Distribution: CentOS 6.2 x86_64 GNU/Linux
Posts: 59

Rep: Reputation: 19
Print only specific rows in a text file


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 04:25 PM.
 
Old 04-24-2009, 05:07 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 04-24-2009, 05:33 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,432

Rep: Reputation: 826Reputation: 826Reputation: 826Reputation: 826Reputation: 826Reputation: 826Reputation: 826
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
 
Old 04-24-2009, 07:18 PM   #4
Mike_V
Member
 
Registered: Apr 2009
Location: Boston MA
Distribution: CentOS 6.2 x86_64 GNU/Linux
Posts: 59

Original Poster
Rep: Reputation: 19
You guys are awesome!
 
  


Reply

Tags
awk, print


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:49 AM
How to print data in rows and columns suran Linux - General 3 03-15-2009 02:53 PM
deleting 100 rows in text file (1-100) via terminal itz2000 Linux - Newbie 5 01-17-2006 11:19 PM
SED - display text on specific line of text file 3saul Linux - Software 3 12-29-2005 04:32 PM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM


All times are GMT -5. The time now is 03:20 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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration