Replace comma with newline in sed

I have a file of id's that are comma separated. I'm trying to replace the commas with a new line. I've tried:

sed 's/,/n/g' file

but it is not working. What am I missing?


改用tr代替:

tr , 'n' < file

Use $'string'

You need a backslash-escaped literal newline to get to sed. In bash at least, $'' strings will replace n with a real newline, but then you have to double the backslash that sed will see to escape the newline, eg

echo "a,b" | sed -e $'s/,/n/g'

sed 's/,/
/g'

适用于Mac OS X.

链接地址: http://www.djcxy.com/p/47134.html

上一篇: 使用Sed替换包含字符串的整行

下一篇: 在sed中用逗号替换逗号