GNU sed long substitutions

Viewed 41

I have long sed substitution expressions in a bash script.

I don't particularly like having such long lines, is it possible to have them split on several lines, i.e.

sed -r -e 's/
    match/
    replacement/
    options'

This would avoid ending up with lines that have 100+ characters, but i've never seen this before using sed.

1 Answers

Perl will let you do this - I recommend looking that up if it's an option -
but in sed you can still use a quoted line break, if perhaps not with the indentation.

sed -r -e 's/'\
'match/'\
'replacement/'\
'options'

In use:

$: echo this needs some match | sed -r -e 's/'\
> 'match/'\
> 'replacement/'\
> 'g'
this needs some replacement
Related