Operating System - HP-UX
1819931 Members
3128 Online
109607 Solutions
New Discussion юеВ

How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

 
Mannoj
Occasional Advisor

How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX?
13 REPLIES 13
Ganesan R
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Hi,

Use this command.

awk -v line=10 "NR==line" file_name -> to display 10th line.

awk -v line=20 "NR==line" file_name -> to display 20th line
Best wishes,

Ganesh.
Ganesan R
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Hi,

You can also use this command.

sed -n '10 p' < file name -> to display 10th line

sed -n '20 p' < file name -> to display 20th line

Best wishes,

Ganesh.
Oviwan
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

you can use sed:

sed -n '10,20p' >

source: http://www.student.northpark.edu/pemente/sed/sed1line.txt
V. Nyga
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

cat fstab.org | awk '{if (NR >9) {print $0}}' | awk '{if (NR <21) {print $0}}'

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Mannoj
Occasional Advisor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Excellent as this is my first day to register on to this blog... that was a gud solution !!!!
V. Nyga
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Ups - sorry for the first post:

cat fstab.org | awk '{if (NR >9) {print $0}}' | awk '{if (NR <12) {print $0}}'

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
V. Nyga
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

has to be of course :-)

V.
*** Say 'Thanks' with Kudos ***
Oviwan
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

so don't forget so say thanks with hp points ;)
Ganesan R
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Hi Manoj,

You can play this trick with head and tail also. see below.

# head -10 filename |tail -1 -> display 10th line
# head -20 filename |tail -1 -> display 20th line.

Best wishes,

Ganesh.
sreekanthtm
Trusted Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Hi Ganesan,...

Please read question again...
He wants display lines from 10 to 20( 10,11,12....up to 20). Not exactly 10th and 20.

Rgds
Sreekanth
Ganesan R
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Yes Sreekanth, I misread the question.

Manoj, use this command.

#sed -n '10,20p'
Best wishes,

Ganesh.
Hein van den Heuvel
Honored Contributor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

awk 'NR==10,NR==20'

perl -ne 'print if $.>=10; last if $.>=20'

Hein.
Mannoj
Occasional Advisor

Re: How to display or cat 10th line to 20rth line of a text file have 100 lines in HP UNIX

Hi ... thanx to every one who replied...

I used sed -n '10,20p' which matched my requirement..

Excellent job !!!!