Get line number

Hi,

How do i get line number of a variable which contains entire line
and then capture all lines till EOF ?

For eg .

Variable vr will contain the string "this is a string"

I need to get line number of this line in the file and then starting from this number till EOF
I want to capture all lines in between

you can get line using following command

grep -n $vr filename | cut -d: -f1

note:- vr = "this is a string"

Now how do i capture all lines till EOF?

If all you need is the lines from whatever $vr holds till EOF, then

sed -n "/$vr/,/G/p" yourfile.txt > out.txt

#! /usr/bin/ksh

while read line
do
basestr="this is a string"
if [[ $line != $basestr ]]
then
continue
fi
echo "abc" # start processing file from here
done < abc

Why /G/ ?

sed -n "/$vr/,\$p" yourfile.txt > out.txt

Jean-Pierre.

sed -n "/$variable/,$ p" inputfile > outputfile

please note the double quotes for variable substitution.

Darn... I had sed -n "/$vr/,$p" yourfile.txt > out.txt with me and it didnt work. I forgot about escaping it.. aarg.. long day !!
Thanks !

what is $p here...and by using this sed -n "/$vr/,/G/p" yourfile.txt > out.txt
i don't get all the lines...it prints only a few lines...

You are reading it wrong; \$ is end of file and p is print. And with /G/p it will only print through the first line matching G, instead of through end of file.

nilesrex' example is identical, it uses a space between $ and p to prevent the $ from being interpreted as a variable (and so the backslash before the $ is not strictly necessary in that case).

Finally, you could mix single and double quotes to get $vr expanded as a variable but keep $p literal:

sed -n "/$vr/",'$p' yourfile.txt > out.txt