0

I wrote the following sed code that I haven't found the way to make it work...

sed -is 's/documentclass\{standalone\}/documentclass\[class\=memoir\]\{standalone\}/gp' *.tex 

Am I using escape sequences the wrong way? The following is the error returned:

sed: -e expression #1, char 76: Invalid content of \{\} 

1 Answer 1

2

In BRE (basic regular expression) mode (i.e. without the -E or -r command line option) braces are not special, while escaped braces are used for quantifiers like \{1,3\}. The error message is because standalone can't be parsed as a numeric quantifier. So you want {standalone}:

$ printf '%s\n' 'documentclass{standalone}' | sed 's/documentclass{standalone}/documentclass[class=memoir]{standalone}/gp' documentclass[class=memoir]{standalone} documentclass[class=memoir]{standalone} 

Alternatively keep the escaped braces, but use ERE (extended regular expression) mode:

$ printf '%s\n' 'documentclass{standalone}' | sed -r 's/documentclass\{standalone\}/documentclass[class=memoir]{standalone}/gp' documentclass[class=memoir]{standalone} documentclass[class=memoir]{standalone} 

Note that in either case, nothing in your RHS needs escaping.

See also:

Note also that at least in GNU sed, -is will edit the file in-place, creating a backup file with suffix s. If you want to pass the -i and -s options you must do so separately or in the other order -si. However iirc -i implies -s so the latter is likely superfluous.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.