Hi. I am currently working on a script, but have encountered some difficulty with sed. The said line is as follows:
sed "s/^($oname)\(.*\)$/($nname)\1/" tempm >edited
The purpose of this line is to look through the text file tempm
, which contains only one line of text at a given time, and if it begins with a pattern that matches exactly the variable oname
, replace that portion with the variable nname
. Both oname
are strings that consists of a single word (i.e. oname could be ab and nname could be bc) Finally, the edited version of the text would be saved into a new file called edited
Unfortunately, this line does not function correctly. tempm
, which I know begins with what is in oname
, is not edited into a desired string, and thus the file edited
is just the same as tempm
So, if you guys can figure out what's wrong, thanks in advance.
Note: I am really a newb when it comes to shell. If you do find what's wrong, explanation would be greatly appreciated.