I wish to use sed in ubuntu to replace a row in a file file.txt.
my row starts with a certain pattern foo followed by any number of any characters. I wish to replace this with foo='x'. I was trying to use the following command from bash:
sed -i 's/^foo*/foo='x'/g' file.txt
Obviously the ' symbol brakes the string transferred to sed. Moreover, the regular expressions don't sim to work for me when I remove the problematic symbol. I simply replace only the pattern foo and not the whole row.
For example the original file.txt:
foo='bla'
The requested result file.txt:
foo='SomethingElse'
I tried a number of variables such as: sed -i 's/\^foo\*/foo=\'x\'/g' file.txt to no avail. I could not find information on the subject online though I am sure this is not the first time someone encountered this problem.
How do I use ' in the target (or the pattern I am searching for that matter)?
And what is up with the regex in this approach?