sed: -e expression #1, char 37: unterminated `s' command

revaljilji

Hi I'm trying to change the content of the multiple files in the folder. I encountered sed error while trying to iterate through array where I store names of the files I need to edit. I tried to use the specific element of the array "${len_1[0]}" and it worked perfectly.

Here's what I've done so far:

len_1=($(find . -name "*.dita"))
len=${#len_1[@]}
echo $len

for ((i=0; i<=len; i++)); do
    apps=$(grep -Po 'appname="\K[^"]+' ${len_1[$i]}) && 
        title=$(grep -Po '<title>\K[^</title>]+' ${len_1[$i]}) && 
            sed -i "s/_[0-9]\+/_$apps.$title/g" ${len_1[$i]} && 
                sed -i "s/id=\"[0-9]\+\"\+/id=\"$apps.$title\"/g" ${len_1[$i]};
    done

As stated before

apps=$(grep -Po 'appname="\K[^"]+' ${len_1[0]}) && 
    title=$(grep -Po '<title>\K[^</title>]+' ${len_1[0]}) && 
        sed -i "s/_[0-9]\+/_$apps.$title/g" ${len_1[0]} && 
            sed -i "s/id=\"[0-9]\+\"\+/id=\"$apps.$title\"/g" ${len_1[0]};

works perfectly.

The error I get is:

sed: -e expression #1, char 37: unterminated `s' command
sed: -e expression #1, char 33: unterminated `s' command
sed: -e expression #1, char 36: unterminated `s' command
sed: -e expression #1, char 36: unterminated `s' command
sed: -e expression #1, char 37: unterminated `s' command
sed: -e expression #1, char 39: unterminated `s' command
sed: -e expression #1, char 34: unterminated `s' command
ilkkachu

If you have multiple matches, grep -o will produce multiple lines of output. And newlines end sed commands:

$ echo abcabbcd | grep -o 'ab*'
ab
abb

$ repl=$(echo abcabcd | grep -o 'ab*')
$ sed -e "s/foo/$repl/"
sed: -e expression #1, char 8: unterminated `s' command

Also, [^</title>]+ means "one or more characters that are not any of ^, <, /, t, i, l, e, or >". It's probably not what you actually want:

$ echo '<title>abcdefgh</title>' | grep -Po '<title>\K[^</title>]+'
abcd

You could use the equivalent when the separator is just one character, e.g. "[^"]*" is ok. But here something like <title>\K.*?(?=</title>)' might work better:

$ echo '<title>abcdefgh</title> <title>foobar</title>' | grep -Po '<title>\K.*?(?=</title>)'
abcdefgh
foobar

(Though I would avoid tricks like \K and lookaheads, and use the simpler perl -lne 'print $1 if m,<title>(.*?)</title>,' or post-process the output instead, but that's my preference.)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

bash - sed: -e expression #1, char 15: unterminated `s' command

From Dev

sed: -e expression #1, char 35: unterminated `s' command

From Dev

sed: -e expression #1, char XX: unterminated `s' command

From Dev

sed: -e expression #1, char 5: unterminated `s' command

From Dev

sed Error sed: -e expression #1, char 7: unterminated `s' command

From Dev

sed: -e expression #1, char 44: unterminated address regex

From Dev

sed: unterminated 's' command`

From Dev

sed: -e expression #1, char 1: unknown command: `''

From Dev

sed: -e expression #1, char 1: unknown command: '|'

From Dev

Why does sed outputs "char 53: unterminated `s' command"

From Dev

bash sed: -e expression #1, char 21: number option to `s' command may not be zero

From Dev

sed command : unterminated `s' command

From Dev

sed: -e expression #1, char 4: unknown command:

From Dev

sed: -e expression #1, char 10: missing command

From Dev

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

From Java

Sed unterminated 's command in script

From Dev

SED not working [unterminated `s' command]

From Dev

SED not working [unterminated `s' command]

From Dev

SED: unterminated `s' command at hyphen

From Dev

sed: -e expression #1, char 23: unknown option to `s'

From Dev

/bin/sed: -e expression #1, char 56: unknown option to `s'

From Dev

sed: -e expression #1, char 3: unexpected `,'

From Dev

sed unterminated `s' command in subprocess.call

From Dev

sed unix error: unterminated 's' command

From Dev

`sed: -e expression #1, char 4: unknown command:` but the line endings are fine

From Dev

sed: -e expression #3, char 59: unknown option to `s'

From Dev

sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

From Dev

sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

From Dev

ssed Unterminated s command

Related Related

  1. 1

    bash - sed: -e expression #1, char 15: unterminated `s' command

  2. 2

    sed: -e expression #1, char 35: unterminated `s' command

  3. 3

    sed: -e expression #1, char XX: unterminated `s' command

  4. 4

    sed: -e expression #1, char 5: unterminated `s' command

  5. 5

    sed Error sed: -e expression #1, char 7: unterminated `s' command

  6. 6

    sed: -e expression #1, char 44: unterminated address regex

  7. 7

    sed: unterminated 's' command`

  8. 8

    sed: -e expression #1, char 1: unknown command: `''

  9. 9

    sed: -e expression #1, char 1: unknown command: '|'

  10. 10

    Why does sed outputs "char 53: unterminated `s' command"

  11. 11

    bash sed: -e expression #1, char 21: number option to `s' command may not be zero

  12. 12

    sed command : unterminated `s' command

  13. 13

    sed: -e expression #1, char 4: unknown command:

  14. 14

    sed: -e expression #1, char 10: missing command

  15. 15

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

  16. 16

    Sed unterminated 's command in script

  17. 17

    SED not working [unterminated `s' command]

  18. 18

    SED not working [unterminated `s' command]

  19. 19

    SED: unterminated `s' command at hyphen

  20. 20

    sed: -e expression #1, char 23: unknown option to `s'

  21. 21

    /bin/sed: -e expression #1, char 56: unknown option to `s'

  22. 22

    sed: -e expression #1, char 3: unexpected `,'

  23. 23

    sed unterminated `s' command in subprocess.call

  24. 24

    sed unix error: unterminated 's' command

  25. 25

    `sed: -e expression #1, char 4: unknown command:` but the line endings are fine

  26. 26

    sed: -e expression #3, char 59: unknown option to `s'

  27. 27

    sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

  28. 28

    sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

  29. 29

    ssed Unterminated s command

HotTag

Archive