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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -