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 11-16-2008, 11:52 PM   #1
sir_com
Member
 
Registered: Feb 2008
Posts: 31

Rep: Reputation: 15
Viewing specified number of lines


Hi All,

Here is the scenario...

I have a file say "test". File contains 40 lines. I want to view only lines between 20 to 30 (inclusive of 20th line & 30th line).

What command to use to achive the same? Please guide.

Thanks,
sir_com
 
Old 11-17-2008, 12:22 AM   #2
centos82
Member
 
Registered: Sep 2008
Distribution: CentOS
Posts: 75

Rep: Reputation: 16
I have two kind of simple solutions for you.

1. If your file will always be 40 lines long then you can do:

cat filename|tail -20|head -10

2. If you don't know how long your file will be but you know you want lines 20 to 30 you can do

totallines=$(cat filename|wc -l)
cat filename|tail -$( echo $(( totallines - 20 )) )|head -10
 
Old 11-17-2008, 01:27 AM   #3
sir_com
Member
 
Registered: Feb 2008
Posts: 31

Original Poster
Rep: Reputation: 15
Thanks centos82. Thanks a lot buddy. I got it now.
 
  


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
number of lines for runlevel 3 RAFAL Linux - General 3 07-24-2008 12:53 PM
Reading the number of Lines in a File Mistro116@yahoo.com Programming 31 11-24-2005 01:36 AM
count total number of lines in several files xushi Programming 5 11-12-2005 05:42 PM
output number of blank lines tjgadu Linux - Newbie 7 06-09-2005 05:01 PM
cat: output specific number of lines mikeshn Linux - Software 3 12-31-2003 01:15 PM


All times are GMT -5. The time now is 06:40 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