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

python - RuntimeError: can't re-enter readline -

python - PyInstaller UAC not working in onefile mode -

php - Need to store a large amount of data in session with CI 3 but on storing large data in session it is itself destorying automatically -