for p in "$CSV"; do
LINEA=$(cut -d',' -f1 $p | sed '1d')
LINEB=$(cut -d',' -f2 $p | sed '1d')
if grep -iq "$LINEA" "$SVG"; then
sed '/g id=\"..\"/a style=\"fill:'"$LINEB"';\"' $SVG > temp.svg
echo "ERROR"

When I execute this script with two files I get the following error:

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

2 Answers 2


some seds will tolerate a [aic] command which is not immediately followed by a backslash-escaped newline and then all of the relevant text like:

sed '/address/atext'

...and even for those that do tolerate it without the escaped newline, what they might do with leading white-space is implementation-specific as well, so...

sed '/address/a text'

...may come out the same as...

sed '/address/atext'

...the portable and standardized way to write any of those is...

sed '/address/a\
text and embedded newline\
more appended text
/next command/...'
  • Using the same sed command in a shell script, with GNU sed v2.05 on Debian 1.1, I receive the error, sed: Extra characters after command, but on GNU sed 4.7 on Debian 9, I do not.
    – jimjamz
    Feb 8, 2023 at 22:47

Order of sed flags may output error extra characters after command

This is wrong:

sed -i fileName -r 's/a/b/g'


sed -r 's/a/b/g' -i fileName
  • 1
    This is correct information, but not relevant to the code shown in the current question.
    – Kusalananda
    Dec 15, 2021 at 13:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .