>Hello,
>I am using ksh on HPUX 10.2 and I need help on the following:
>If I have a text file 5000 - 6000 lines long and I grep for a string using
>the -l option to print the line number that the string occurs on, is there
>a way, through ksh to print out the lines starting from the position
>returned from grep to the end of the file? So if grep finds the string on
>line 1500 of 3000 lines, I want to print lines 1500 - 3000.
To get lines 1500-3000 of a file use one of these:
head -3000 infile | tail +1500
sed -n "1500,3000 p" infile
To get from line 1500 to the end, use one of these:
tail +1500 infile
sed -n "1500,$p" infile
sed "1,1499d" infile
If you want to get from the first line containing a regular expression
to the end of the file:
sed -n "/regexp/,$p" infile
awk '/regexp/||c==1{c=1;print}' infile
see
man sed
man head
man tail
man awk
man gawk
or you can*around the way you're going, something like:
sed -n "`grep -n 'regexp' infile | cut -f1 -d: `,$ p" infile
or
tail +`grep -n 'regexp' infile | cut -f1 -d: ` infile
Yuck!!! :-)
FWIW, my grep -l doesn't do what you want. It's grep -n on my system.
Chuck Demas
Needham, Mass.
Quote:>This is just an
>example, chances are I won't be printing 1500 lines to the screen. I've
>tried using "tail -n <line returned by grep> textfile" but I've had mixed
>results when working with large files. This will be a temp file I'm working
>with so removing lines 1 - 1499 is fine too. Any ideas?
>Thanks in advance.
>Barry
--
Eat Healthy | _ _ | Nothing would be done at all,
Die Anyway | v | That no one could find fault with it.