-1

While using the command "sed" for find and replace, I wanted to know how one could find a constant and replace it with a variable inside the quotation syntax of sed?

I wanted to replace constant 3 with variable name "hourid" Here is what I tried.

sed -i 's@3@hourid$@g' file_name.txt

I want to know how to provide a right syntax for replacing variable "hourid"

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

1 Answers1

0
sed -i "s/3/$hourid/g" file_name.txt

Or

sed -i 's/3/'"$hourid"'/g' file_name.txt
user1133275
  • 5,574