Why "Extra Characters After Command" Error Shown for the Sed Command Line Shown

why extra characters after command error shown for the sed command line shown?

It appears that some of the variables are expanding to values that contain a /. Use a different delimiter that isn't contained in any of the variables, e.g.

sed 's@dump 0 $2 $3 $4 $5@dump 1 $2 $3 $4 $5@g' base_file.properties

(Your first command isn't a valid sed expression.)

Error on sed script - extra characters after command

sed can not automatically determine whether you intended a parameter to be a script file or a script string.

To run a sed script from a file, you have to use -f:

$ echo 's/hello/goodbye/g' > demo.sed

$ echo "hello world" | sed -f demo.sed
goodbye world

If you neglect the -f, sed will try to run the filename as a command, and the delete command is not happy to have emo.sed after it:

$ echo "hello world" | sed demo.sed
sed: -e expression #1, char 2: extra characters after command

sed error complaining extra characters after command

To use the alternate delimiters for addresses, you need to use backslash - \

sed "\:$PWD:d" < $myfile

Should work.

Of course for this exact example, grep -v is probably easier.

sed: -e expression #1, char 2: extra characters after command

So, a sed command consists of an optional address (which indicate(s) the lines that you want to touch, either by specifying line numbers or by specifying a regex), followed by a command, followed by whatever arguments or options that command takes.

Your command passes this script to sed:

db.default.url="jdbc:mysql://localhost:3306/${DB_NAME}"

so there's no address; the command is 'd' (meaning "delete and move on"); and the rest of the script, b.default.url="jdbc:mysql://localhost:3306/${DB_NAME}", doesn't actually make sense to sed, because the 'd' command doesn't take any arguments or options.

Instead, I think you want this script:

s#^db.default.url=.*#db.default.url="jdbc:mysql://localhost:3306/xyz123"#

which uses the 's' command to replace anything matching the regex ^db.default.url=.* with the string db.default.url="jdbc:mysql://localhost:3306/xyz123". (Note: usually we use / to set off the regex and replacement, but in this case I've used # to avoid having to escape every occurrence of / inside the replacement string.)

So your full Bash command, which runs that sed script, would look like this:

sed -i \
's#^db.default.url=.*#db.default.url="jdbc:mysql://localhost:3306/'"$DB_NAME"'"#' \
/root/local.conf

Sed Error extra characters at the end of g command

Was missing the -e.

This did the job:

sed -i -e 's:io.gatling.app.Gatling:io.gatling.app.Gatling -s "redirects.RedirectLoad" -df /opt/gatling/user-files/data:g' gatling.sh

How to fix sed command on MacOS with error extra characters after \ at the end of c command?

Try this on BSD (OSX) sed:

sed -i.bak '/"appId"/c\ 
"appId": "'${applicationId}'",
' "$capacitorConfigJson"

Note that there is a space after c\

BSD sed: extra characters at the end of d command

The simplest solution is to put a semi-colon after the d (the spaces shown are optional):

sed -e '3,6 { /This/d; }' pets.txt

BSD sed is fussier about the layout than GNU sed. There are a number of GNU extensions that are not part of BSD sed, and this is one. The semi-colon isn't the universal solution to problems, though it does solve many of them. You could also spread the commands out over multiple lines, or put them in multiple -e options, or various other 'tricks'.



Related Topics



Leave a reply



Submit