SED { command fail

170 Views Asked by At

On MKS SED for Windows, this

TYPE Q:\temp\curtainssetspread.M3U | SED -E "/z/{s_a_b_}"

fails with

sed: garbage after command

Why?

This usage accords correctly with docs:

a,b{    groups all commands until the next matching }, so that sed executes the entire group only if the { command is selected by its address(es).
1

There are 1 best solutions below

8
HTNW On

According to POSIX, the } must be preceded by a newline. I'm not sure what MKS does, but the beauty of having a standard is that the following should work on all systems (using multiple -es joins each string together with newlines in between):

sed -e "/z/{s_a_b_" -e "}"

If it doesn't work, it's a bug in MKS and should be reported, as they say their sed is POSIX-compliant.

I do suggest following Benjamin's advice and just doing

sed -e '/z/s_a_b_'

if possible, though.