0

After some text manipulations I got the output: " 75 queen". I sent it like this:

..( 75 queen ).. | sed 's/ \([0-9]*\) \(q.*) /The word \2 with \1 appearances.'

For this code I got the error "sed: -e expression #1, char 66: unterminated `s' command. What does it mean?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
NavGino
  • 1
  • 1

1 Answers1

1

There are several issues that need to be solved in your sed expression:

  1. The replace command must end with / plus any modifiers.

  2. There are several regex "flavors" and sed uses the Basic POSIX regular expression, which means that () should be escaped in order to capture matching groups. Check this answer for details.

  3. It seems you want to capture 75 and queen. To do that you need to specify that the first group should match any number of digits and the second group should capture q followed by any number of characters. * will match 0 or more of repetitions and + (that should be escaped) will match 1 or more repetitions.

Considering that, the following sed expression should do the trick:

echo '..( 75 queen )..' | sed 's/ \([0-9]\+\) \(q.*\) /The word \2 with \1 appearances./'
Community
  • 1
  • 1
Marcelo Cerri
  • 162
  • 1
  • 10