0

I'm trying to use:

sed -n '/String1/,/String2/p' Filename

to print all lines between String1 and String2. Although I want to add String1 as a user input so,

read $userinput
sed -n '/$userinput/,/String2/p' Filename. 

But as the input is within quotation is is read as the string $userinput instead of the given input.

1 Answers1

0

Simply like this:

read userinput                         # without sigil '$'
sed -n "/$userinput/,/String2/p" file  # with double quotes

Learn how to quote properly in shell, it's very important :

"Double quote" every literal that contains spaces/metacharacters and every expansion: "$var", "$(command "$var")", "${array[@]}", "a & b". Use 'single quotes' for code or literal $'s: 'Costs $5 US', ssh host 'echo "$HOSTNAME"'. See
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words