LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2012, 10:11 AM   #1
raybies
LQ Newbie
 
Registered: Apr 2009
Location: Utah
Distribution: fedora and red hat enterprise
Posts: 6

Rep: Reputation: 0
Question How do I cat a range of lines?


Is there a simple commandline way to cat a file (perhaps there are some options I'm unaware of) that will show a range of lines in a text file?

I know tail and head have nice options for showing front and back ends of files, but I wanna see a range in the middle.

Example: if -s was the starting line number and -e was the ending line number, and rangecat was this made up command that worked happily according to my spec...

rangecat -s 2000 -e 2004 textfile.txt

would output to my terminal lines 2000-2004 of textfile.txt.

Last edited by raybies; 03-14-2012 at 10:18 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-14-2012, 10:15 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,131
Blog Entries: 2

Rep: Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833Reputation: 4833
Simple: In your example just use head to display the first 2004 lines and then pipe the output through tail to display the last 4 lines. Done.
 
2 members found this post helpful.
Old 03-14-2012, 10:21 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Or use sed:
Code:
sed -n 2000,2004p file
 
1 members found this post helpful.
Old 03-14-2012, 10:29 AM   #4
raybies
LQ Newbie
 
Registered: Apr 2009
Location: Utah
Distribution: fedora and red hat enterprise
Posts: 6

Original Poster
Rep: Reputation: 0
thanks folks. I should've known sed had an option for this sort of thing... Heh... then again gazing at sed for too long causes madness...
 
  


Reply


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
cat: output specific number of lines mikeshn Linux - Software 8 01-24-2017 12:08 PM
[SOLVED] CAT command | multiple lines to multiple lines udiubu Programming 11 10-28-2011 07:09 AM
Using CAT / GREP to remove a set of lines from a file wesgarner Linux - Newbie 13 11-14-2009 11:41 AM
can't see all 20,160 lines in a file when 'cat filename' dave247 Debian 4 10-25-2008 06:13 PM
cat a range cachemonet Linux - General 9 06-07-2006 12:54 PM


All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration