Bash:使用bash,单独的行按Enter键

时间:2013-10-08 23:52:05

标签: regex bash shell

例如,在文件a.txt中我有

  Apple, Orange


我想要的输出在b.txt

  Apple
  Orange

如何在文字中分隔线条? 我尝试了这个,但没有工作。它只是插入字符n

   sed 's/, /\n/g' a.txt > b.txt

2 个答案:

答案 0 :(得分:1)

使用sed行中的输入。它将被视为换行符。例如:

ani ~]$ echo "Apple, Orange" | sed 's/, /\
/g'
Apple
Orange
ani ~]$ 

注意反斜杠

答案 1 :(得分:1)

如果您想要一个不涉及sed换行符的单行解决方案,可以使用tr

echo "Apple, Orange" | tr -s ', ' '\n'

对于您的文件:

<a.txt tr -s ', ' '\n' > b.txt

h / t @WilliamPursell

相关问题