unix - sed with line numbers as variables -
i want specific lines using sed
, first line , last line stored in variables.
here example, want lines between first line (here line number 5) , last line (here number 8), , use grep search specific word.
firstline=5 lastline=8 sedresult="$(sed -n "$firstline,$lastline p" text.txt | grep word -aii)"
but having errors. errors :
sed: -e expression #1, char 5: unexpected `,'
what proper way use variables line numbers ?
your initial expression has broken double quotes usage. should be:
firstline=5 lastline=8 sedresult=$(sed -n "$firstline,$lastline p" text.txt)
Comments
Post a Comment