tr command - how to replace the string “\n” with an actual newline (\n)

后端 未结 2 475
清酒与你
清酒与你 2020-12-29 18:22

I would like to use the tr command to replace all occurrences of the string \"\\n\" with a new line (\\n).

I tried tr \'\\\\n\' \'\\n\' but

2条回答
  •  梦毁少年i
    2020-12-29 18:45

    Here's how to do it with sed:

    sed 's/\\n/\n/g'
    

    Example usage:

    To replace all occurrences of \n in a file in-place:

    sed -i 's/\\n/\n/g' input_filename
    

    To replace all occurrences of \n through a pipe, and save into another file

    cat file1 file2 file3 file4 | sed 's/\\n/\n/g' > output_file
    

提交回复
热议问题