Operating System - HP-UX
1826414 Members
4154 Online
109692 Solutions
New Discussion

any way to cat a file from 3rd line....

 
SOLVED
Go to solution
boomer_2
Super Advisor

any way to cat a file from 3rd line....

Hi guys,
Is there any way that i can cat a file and see the contents fro 3 line onwards.....leaving head and tail.........
i.e. if i have a file containing 10 lines........i should be able to view the file using cat command ,but from 3rd line ....onwards..........
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor
Solution

Re: any way to cat a file from 3rd line....

Hi :

# sed -n '3,$p' file

The "$" means the end-of-the-file.

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: any way to cat a file from 3rd line....


perl -n 'print if $. > 2' file

Hein.
boomer_2
Super Advisor

Re: any way to cat a file from 3rd line....

thnx James,Hein...........
Ivan Krastev
Honored Contributor

Re: any way to cat a file from 3rd line....

Use:

cat file | awk 'NR > 2'


regards,
ivan
James R. Ferguson
Acclaimed Contributor

Re: any way to cat a file from 3rd line....

Hi (again):

I like the 'awk' solution but not with the additional 'cat' process!

# awk 'NR > 2' file

Let 'awk' open the file itself rather than having both 'cat' and 'awk' do I/O.

As you can see, your solution exists easily in 'sed', 'awk' or 'perl'. From a resource standpoint, I suspect that 'sed' is probably the fastest with the smallest memory footprint for this task.

Regards!

...JRF...
Michael Mike Reaser
Valued Contributor

Re: any way to cat a file from 3rd line....

I like everyone's awk, sed and perl solutions, but I'm wondering - what's wrong with a simple

tail -n +3 file

?
There's no place like 127.0.0.1

HP-Server-Literate since 1979
James R. Ferguson
Acclaimed Contributor

Re: any way to cat a file from 3rd line....

Hi:

>Mike: I like everyone's awk, sed and perl solutions, but I'm wondering - what's wrong with a simple tail -n +3 file

Nothing. In the words of Perl: TMTOWTDI

Regards!

...JRF...
Mike Reaser
Advisor

Re: any way to cat a file from 3rd line....

JRF:

>Nothing. In the words of Perl: TMTOWTDI

:) :) :)

Seriously, I didn't know if tail was just too much of a Resource Hog to consider.
Sandman!
Honored Contributor

Re: any way to cat a file from 3rd line....

Yet another way of doing the same thing:

# ex -s +'3,$p|q!' file