Re: Query on using command "SED" for replacing text in bash shell
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"
Your request is not too clear. Do you want to replace a constant string ("3") in your text with the expanded value of a shell variable ( $hourid )? Then, try double quotes, as single quote prevent expansion:
sed "s@2@${hourid}@g" file
Be careful not to trigger on false positives (e.g. 13, 3567, etc.)