1
How to add a line break in a pipe received output, using sed, only for cases that fit the established pattern?
I used sed "s/.*oo.*/&\n/"
unsuccessfully. The pattern is OK, but the addition of the new line is not. I need to know what to put there where it is \n
.
Examples of results I hope:
Sem Match:
echo 'bravo bar' | sed "s/.*oo.*/&\n/"
expected output:
bravo bar
Match:
echo 'foo bar' | sed "s/.*oo.*/&\n/"
expected output:
foo
bar
The output of your command is:
foonbar
– neoprofit
It’s not no... Tested before posting.
– Henrique Barcelos
In which OS? In OS X the result is
foonbar
– neoprofit
That’s why on Mac the line break is
\r
, nay\n
. Just make the switch to work.– Henrique Barcelos
if I switch to r
foorbar
– neoprofit
I’ve never used OS X, it’s probably some question with Escaping. Try with
\\r
and see the result.– Henrique Barcelos
I’ll use the other answer, but thanks anyway!
– neoprofit
But it works with
\\r
? Now even I want to know the answer– Henrique Barcelos
output:
foo\rbar
– neoprofit
the standard version of
sed
in OS X is not thegnu sed
, so the differences in output. Output works as expected ingnu sed
. Out of curiosity, thesed
default on OS X is the same as found on Freebsd.– Bruno Coimbra
@Brunocoimbra, this is always a headache! Fortunately the homebrews and the like have the gnused version of easy installation. In some cases the Macs have gnused installed with the name gsed or gnused. gnused (and gnu awk) functionality is significantly richer.
– JJoao