Grepping text by providing line numbers.

Dear Friends,
I have a flat file from which I want to grep line no. 7,10, 19 to 35, 37.
How can it be done?

Thank you in advance
Anushree

Hi.

When you say "grep lines", do you mean extract lines?

There are a number of tools that can do this.

But based on what you asked, this should work...

sed "7p;10p;19,35p;37p;d" my_file | grep "....."

awk 'NR ~ /^(7|10|19)$/' file

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris:

awk 'NR~/^7|1[09]|2[0-9]|3[0-5,7]$/' infile

One way to do it in perl:

perl -ne 'BEGIN{foreach $i (7,10,(19..35),37){$x{$i}=1}}{print if $x{$.}==1}' infile

tyler_durden

I have to read more carefully,
I corrected my post.

Using the same logic with Perl:

perl -ne'$.=~/^7|1[09]|2[0-9]|3[0-5,7]$/and print' infile

Hey friends
Almost all solutions worked fine
Thank you for the quick reply.
Take care.