bash - How to include variables in the sed command? -
grep -f "$name" -a1000 filename | sed -n '1p;19p;24p' assume let a=10,b=20,c=30.in above grep command can use '$ap;$bp;$cp' instead of '1p;19p;24p'?
another thing, i've given -a1000. implies starting 1p considers till 1000 line , right? need search throughout file without giving number.
if want include variables inside quotes, need use " instead of '.
if want add alphanumeric suffix variable need indicate it's not part of it's name.
sed -n "${a}p;${b}p;${c}p" or:
sed -n "$a"'p;'"$b"'p;'"$c"'p'
Comments
Post a Comment