using sed to print next line after match
Posted
by
smokinguns
on Super User
See other posts from Super User
or by smokinguns
Published on 2012-11-07T01:21:04Z
Indexed on
2012/11/07
5:03 UTC
Read the original article
Hit count: 404
I came across various examples on printing next line after a match, that use awk and sed. I'm using it in my code and it works fine. Now I want to use a variable instead of a hardcoded value for the pattern match. The search pattern string includes forward slashes "/". How do I use a variable that has "/" in it and use it to print the next line after the match? The following doesn't seem to work:
var="/somePath/to/my/home"
val=`echo -e "$someStr" | sed -n ':$var:{n;p;}'`
In this case, val is always blank. I'm using using ":" as the delimiter instead of "/". I'm on a Mac OS X.
© Super User or respective owner