I have a configuraton file that I am editing and on the first pass the is correctly changed but on the next two lines sed returns the lines blank.
The lines to be edited are
word.word.word.database=dbase
word.word.word.username=someone
word.word.word.password=someone
The sed commands I am using are
cat config.file | \sed -e "s/database/$dbname/" > config.file.1
cat config.file.1 | \sed -e "s/username/$dbuser/" > config.file.2
cat config.file.2 | \sed -e "s/database/$password/" > config.file.3
cp config.file.3 config.file
The end result is
word.word.word.database=dbname
word.word.word.username=
word.word.word.password=
Can’t figure out what is going wrong with this. Any help would be great.
Thanks!
$dbname,$dbuserand$passwordare begin treated like shell variables, hence the leading dollar signs. If you’re trying to incorporate shell vars, try:Notice that I’ve added the
-iflag to the above command. It enables in-place editing usingGNU sed. Other types ofsedrequire an extension to be set, like:-i.bakand this creates a back up file; in your case this would be:config.bak.If you’re just looking to get the full list of results, either drop the dollarsigns or use single quotes. For example:
or
EDIT1:
If I’ve completely mis-understood your question, try this:
Results:
EDIT2:
If you have shell vars labelled
$dbname,$dbuserand$password: