This question already has answers here:
Replacing string in linux using sed/awk based
(3 answers)
Closed 2 years ago.
I want to find all instances of #- "${COMPOSER_CONFIG} and replace with - "${COMPOSER_CONFIG} within a file. (Note, the removal of #- )
The command I have come up with is:
sed -i '/#- "${COMPOSER_CONFIG}/- "${COMPOSER_CONFIG}' docker-compose.yml
But I get the error:
sed: -e expression #1, char 25: unknown command: `-'
It appears the minus sign is causing the issue. After researching this I am unable to identify why this is the case.
Any insight greatly welcome.
Try this
sed -i '/COMPOSER_CONFIG/s/#//' docker-compose.yml
Related
This question already has answers here:
sed substitution with Bash variables
(6 answers)
Closed 1 year ago.
i have a config file with this format
http://link:port/username/password/1234
Im using this code to replace the Username1/Password1 with a different Username2/Password2
sed -i -e 's/\/Username1\/Password1/\/Username2\/Password2/g' /etc/config.cfg
Now i want to make this something like
$UsernameOLD = Username1
$PasswordOLD = Password1
$UsernameNEW = Username2
$PasswordNEW = Password2
sed -i -e 's/\/$UsernameOLD\/$PasswordOLD/\/$UsernameNEW\/$PasswordNEW/g' /etc/config.cfg
Could anyone help me getting this ready ?
I found the solution i had to use double quotes instead of '
The working command looks like this:
UsernameOLD=MyOldUsername
PasswordOLD=MyOldPassword
UsernameNEW=MyNewUsername
PasswordNEW=MyOldUsername
sed -i -e "s/\/$UsernameOLD\/$PasswordOLD/\/$UsernameNEW\/$PasswordNEW/" /etc/config.cfg
This question already has answers here:
sed fails with "unknown option to `s'" error [closed]
(1 answer)
How to pass a variable containing slashes to sed
(7 answers)
Closed 2 years ago.
I am trying to replace a variable value in my file using bash.
Input string ----- preprocess_date=06/24/2020_17:00
Expected string ----- preprocess_date=06/24/2020_17:10
I have the value 06/24/2020_17:10 in prep_tmp variable. I have tried the below command:
sed -i s/preprocess_date=.*/preprocess_date=${prep_tmp}/
I'm getting the error sed: -e expression #1, char 43: unknown option to `s'
Can anyone help me on this?
Thanks in advance.
Your command with the 3 seperating /:
sed -i s/preprocess_date=.*/preprocess_date=${prep_tmp}/
^ ^ ^
expands to:
sed -i s/preprocess_date=.*/preprocess_date=06/24/2020_17:10/
^ ^ ^
with 24/2020_17:10/ overflowing after the s command
To solve this problem you can replace all the sperarating / with some other character. I like using the | (but also needs " to ensure that they are not parsed as pipes by a shell)
sed -i "s|preprocess_date=.*|preprocess_date=${prep_tmp}|"
This question already has answers here:
Write Dollar sign in sed command pattern inside makefile
(2 answers)
Closed 5 years ago.
I have a simple sed replacement for a text file:
sed -i 's/Temp_3/$t0/g' ./somefile.txt
When I use it in a bash script everything works fine.
However, if I try to use the same line from a makefile,
the $t is (probably) expanded into the empty string
(there is no variable called t in the makefile) and
Temp_3 is replaced with 0. What is the best way to solve this?
Thanks!
What happens is that make first does its substitutions,
in your case $t with nothing, then runs the command.
You can, or should ;), circumvent this problem by changing your command as follows: change $ with $$;
make will substitute the double $ sign with a single one.
sed -i 's/Temp_3/$$t0/g' ./somefile.txt
This question already has answers here:
How to pass a variable containing slashes to sed
(7 answers)
Closed 1 year ago.
I have this as variable
set var=1920 x 1080p / 23.976 fps /16:9 / High Profile 4.1
and i will replace with sed
sed -e "s/1920/%var%/" movie.txt > movie2.txt.nfo
error output is
ed: -e expression #1, char 30: unknown option to `s'
I do not understand what's wrong
Regards
The problem is with slashes. Your final command will have many slashes coming from the variable itself, which will be confused with the / delimiter you provided in the sed command itself.
Luckily, sed can have any char as the delimiter. Change to something like:
sed -e "s-1920-%var%-"
Now, - won't be confused with / (from the variable).
This question already has answers here:
sed is printing a substituted line twice
(2 answers)
Closed 6 years ago.
The perils of working tired:
sed -i 's/foo/barbazqux/p' example.txt
This made the output file have two copies of any modified line.
Turns out I hadn't removed the p flag from the end of the command. I'd been doing this when testing it on the command line.
Correct command:
sed -i 's/foo/barbazqux/' example.txt