removing new line character from incoming stream using sed

前端 未结 2 1128
不知归路
不知归路 2020-12-24 07:01

I am new to shell scripting and i am trying to remove new line character from each line using SED. this is what i have done so far :

printf \"{new\\nto\\nlin         


        
2条回答
  •  既然无缘
    2020-12-24 07:13

    To remove newlines, use tr:

    tr -d '\n'
    

    If you want to replace each newline with a single space:

    tr '\n' ' '
    

    The error ba: Event not found is coming from csh, and is due to csh trying to match !ba in your history list. You can escape the ! and write the command:

    sed ':a;N;$\!ba;s/\n/ /g'  # Suitable for csh only!!
    

    but sed is the wrong tool for this, and you would be better off using a shell that handles quoted strings more reasonably. That is, stop using csh and start using bash.

提交回复
热议问题