How to remove carriage return in Linux or Unix

‮w//:sptth‬ww.lautturi.com
How to remove carriage return in Linux or Unix

To remove carriage return (CR) characters from a file in Linux or Unix, you can use the tr command.

The tr command is a utility that allows you to translate or delete characters from a file. You can use it to remove CR characters from a file by replacing them with nothing.

Here is an example of how you can use the tr command to remove CR characters from a file:

tr -d '\r' < input.txt > output.txt

This command will read the input.txt file, delete all CR characters, and write the result to the output.txt file.

You can also use the sed command to remove CR characters from a file. For example:

sed 's/\r//g' input.txt > output.txt

This command will read the input.txt file, search for CR characters (\r), and replace them with nothing (//). The result will be written to the output.txt file.

Created Time:2017-10-28 21:39:06  Author:lautturi