FreeKB - carriage returns (\r ^M)
Bash Shell Scripting - carriage returns (\r ^M)

The following two characters are used to represent a carriage return.



Let's say foo.txt is transferred from a Windows system to a Linux system. Windows will end each line with a new line (\n) and carriage return (\r). On Linux, lines only end with a new line (\n), thus sometimes you may want or need to remove the carriage return (\r) from each line.

This command will remove the carriage return (\r) and redirect the results to a new file (bar.txt). This is the common approach because the -i option in sed may fail if the file did not have Full Control permissions on Windows.

sed 's/\r$//' foo.txt > bar.txt


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter d4ca1 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |