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
aju_kup
November 16, 2006, 9:58am
2
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?
vino
November 16, 2006, 10:28am
4
If all you need is the lines from whatever $vr holds till EOF, then
sed -n "/$vr/,/G/p" yourfile.txt > out.txt
aju_kup
November 16, 2006, 10:32am
5
#! /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
aigles
November 16, 2006, 10:52am
6
vino:
If all you need is the lines from whatever $vr holds till EOF, then
sed -n "/$vr/,/G/p" yourfile.txt > out.txt
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.
vino
November 16, 2006, 1:47pm
8
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...
era
July 24, 2008, 5:34am
10
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