LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-21-2010, 12:26 AM   #1
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Rep: Reputation: 1
tail command syntax to print a sequence of line


How to print a sequence of line say line number 10 to 20 of a 50 line file ?
 
Old 12-21-2010, 12:34 AM   #2
Manjunath1847
Member
 
Registered: Mar 2007
Posts: 44

Rep: Reputation: 16
as far as I know, tail is used to print last part of the files. Try head command.
 
Old 12-21-2010, 12:35 AM   #3
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Original Poster
Rep: Reputation: 1
With a combination of tail and head can we do it ?
 
Old 12-21-2010, 01:01 AM   #4
Manjunath1847
Member
 
Registered: Mar 2007
Posts: 44

Rep: Reputation: 16
ya something like that.

tail -n4 main.cpp | head -n2

In this example I am trying to print last 4 lines of the files and output is fed to head which prints the first 2 lines of tail output
 
1 members found this post helpful.
Old 12-21-2010, 01:28 AM   #5
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Original Poster
Rep: Reputation: 1
That Worked !!


Thanks a lot
 
Old 12-22-2010, 05:40 AM   #6
dharanivasan
LQ Newbie
 
Registered: Nov 2010
Posts: 6

Rep: Reputation: 1
You can do using

head -20 test.txt | tail -10
 
Old 12-22-2010, 06:02 AM   #7
mIXpRo
LQ Newbie
 
Registered: Jun 2010
Posts: 10

Rep: Reputation: 0
or if it's a variable :
Quote:
echo $variable | head -20 | tail -10
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Print all PID folders from /proc line-by-line with this format (( PID: command-line )) courteous Linux - Newbie 7 12-12-2010 04:47 PM
Want to print fouth line after resulted line using grep with tail command saurabhmehan Linux - Newbie 10 08-04-2010 11:38 PM
Command line syntax Steve36810 Linux - Newbie 2 02-24-2009 02:29 PM
Ubuntu Server 7.04 command line boot sequence KAOZ_IT Linux - Server 1 07-05-2007 04:28 AM
xmms command line syntax xviddivxoggmp3 Linux - Software 11 03-12-2004 01:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:22 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
Open Source Consulting | Domain Registration