46
18
I find that \n
doesn't work in sed under Mac OS X.
Specifically, say I want to break the words separated by a single space into lines:
# input
foo bar
I use,
echo "foo bar" | sed 's/ /\n/'
But the result is stupid, the \n
is not escaped!
foonbar
After I consulted to google, I found a workaround:
echo 'foo bar' | sed -e 's/ /\'$'\n/g'
After reading the article, I still cannot understand what \'$'\n/g'
means.
Can some one explain it to me, or if there is any other way to do it? Thanks!
Possible duplicate: http://stackoverflow.com/questions/21621722/removing-carriage-return-on-mac-os-x-using-sed
– hyiltiz – 2017-04-19T07:05:30.5001this would probably work too:
echo "foo bar" | tr ' ' '\n'
– glenn jackman – 2011-07-06T18:17:18.1703Thanks for the advice. But currently I just use the above case as an example, I do need to know how to escape a
\n
. – Ivan Z. G. Xiao – 2011-07-06T22:50:01.227