olkkis
April 19, 2012, 3:11am
1
Im trying to use sed to print value that matches the value in variable and all lines after that.
grep "Something" test.txt | sed -e '/{$variable}/,$b' -e 'd'
I cant get it work, if I replace the $variable with the value it contains, it works fine...
Use double quotes instead of single ones to expand variables to it's value.
Regards
Peasant.
---------- Post updated at 02:15 AM ---------- Previous update was at 02:15 AM ----------
Use double quotes instead of single ones to expand variables to it's value.
Regards
Peasant.
olkkis
April 19, 2012, 3:17am
3
peasant:
Use double quotes instead of single ones to expand variables to it's value.
Regards
Peasant.
---------- Post updated at 02:15 AM ---------- Previous update was at 02:15 AM ----------
Use double quotes instead of single ones to expand variables to it's value.
Regards
Peasant.
Now I got error saying
expected newer version of sed
btw, is there way doing this with awk?
Can you post your operating system ?
Can you please post input (test.txt) and $variable and $b values and desired output ?
Regards
Peasant.
use the below instead of sed
awk -v v="$variable" 'a;$0~v{print;a=1}'
1 Like
Hi,
Try this one,
awk -v pat="$var" '$0~pat{a=1}a' file
Cheers,
Ranga:)
zaxxon
April 19, 2012, 4:06am
9
Your basic problem is, that variables inside single quotes '
will not be substituted by the shell. Additionally the grep
could be done by the sed
as well.
Here someone had the same problem:
olkkis
April 19, 2012, 4:31am
10
Thanks, this works fine. I have one more question:
Is it possible to post all the lines after the match but not the matching line?