i have a text file containing some content like that,
some content
replace content
other content
and i have some variables, looking like this:
PATH="/path/to/scriptdir"
PARAMETERS="para1 para2"
FILETOCHANGE="/foo/bar"
Now i want to replace the content in the text file that begins with replace, with the content of the variables PATH and PARAMETERS. The text file should look like that, after the replace:
some content
/path/to/scriptdir/script para1 para2
other content
I just tried the a couple of sed commands, but always i get an error. For example
sed -i "s/^replace.*$/$PATH/script $PARAMETERS/g" $FILETOCHANGE
sed: -e expression #1, char 12: unknown option to `s'
or
sed -i "s|^replace.*$|$PATH/script $PARAMETERS|g" $FILETOCHANGE
sed: -e expression #1, char 58: unterminated `s' command
Can you tell me, what I'm doing wrong?
$PATH
is a special variable that contains paths to executable files, use$path
isntead./
characters. But your second should work, and with the values ofPATH
andPARAMETERS
you've given, the resulting command should be less than 58 characters. Please can you confirm the actual values of these variables?|
instead of backslash works. The issue is probably due to the fact that$PATH
does not contain what you think./data/data/dir/more/scriptname
and i have usually four parameters. I tested the command only with one parameter and it works. Do you know what i have to do, that my command can have more characters or do i have to split my command?