Skip to main content
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
Source Link

Use double quotes to have the var evaluated properly:

$ var=43
$ sed "s/.*had a little lamb.*/Mary had $var little lambs/" file
Mary had 43 little lambs
with fleece as white as
snow. Everywhere that
Mary went, the lamb was
sure to go.

See Jacob Minshall's answerJacob Minshall's answer regarding the .* instead of *.. I had written the sed command from scratch, so I did not notice the error in the original code.

Use double quotes to have the var evaluated properly:

$ var=43
$ sed "s/.*had a little lamb.*/Mary had $var little lambs/" file
Mary had 43 little lambs
with fleece as white as
snow. Everywhere that
Mary went, the lamb was
sure to go.

See Jacob Minshall's answer regarding the .* instead of *.. I had written the sed command from scratch, so I did not notice the error in the original code.

Use double quotes to have the var evaluated properly:

$ var=43
$ sed "s/.*had a little lamb.*/Mary had $var little lambs/" file
Mary had 43 little lambs
with fleece as white as
snow. Everywhere that
Mary went, the lamb was
sure to go.

See Jacob Minshall's answer regarding the .* instead of *.. I had written the sed command from scratch, so I did not notice the error in the original code.

Source Link
fedorqui
  • 8.2k
  • 9
  • 38
  • 76

Use double quotes to have the var evaluated properly:

$ var=43
$ sed "s/.*had a little lamb.*/Mary had $var little lambs/" file
Mary had 43 little lambs
with fleece as white as
snow. Everywhere that
Mary went, the lamb was
sure to go.

See Jacob Minshall's answer regarding the .* instead of *.. I had written the sed command from scratch, so I did not notice the error in the original code.