All Questions
4 questions
2
votes
0
answers
49
views
Does POSIX specify sed -E? [duplicate]
sed uses basic regular expressions (BRE) by default. Some implementations offer an option to switch to extended regular expressions instead.
GNU sed introduced the -r option to do so in version 3.01 ...
0
votes
3
answers
753
views
sed portability: extended regex vs. backslash
We can write the next command in two ways:
# using extended regex
$ echo foobar | sed -E 's/(foo)(bar)/\2\1/'
barfoo
And:
# using backslashes
$ echo foobar | sed 's/\(foo\)\(bar\)/\2\1/'
barfoo
...
4
votes
2
answers
6k
views
Is the use of sed's "a" command to prefix a line portable?
I noticed the following interesting behavior:
$ printf '%s\n' line{1..2} | sed $'1a\\\nPREFIX'
line1
PREFIXline2
$
Interestingly, this behavior is only possible for the last command in a Sed script,...
3
votes
3
answers
769
views
Is it portable to indent the argument to sed's 'i\' command?
I was under the impression from the POSIX specs for sed that it is necessary to left-align the text on the line following the i\ command, unless you want leading whitespace in the output.
A quick ...