Thursday, 21 March 2019

How to Remove CTRL-M characters From a File in UNIX and Linux? Example

If you're working with text files in a UNIX or Linux environment, you may encounter the issue of unwanted control-M characters, which can cause problems with formatting and readability. These characters are also known as carriage return characters, and they can be removed using a few simple commands in the terminal. In this article, we'll go over how to identify and remove control-M characters from your files using UNIX and Linux.

Identifying Control-M Characters

Before we can remove control-M characters from our files, we need to be able to identify them. One way to do this is by using the cat command with the -v option, which displays non-printing characters in a file.

cat -v file.txt


This command will display the contents of the file.txt, showing control-M characters as "^M" in the output. If you see these characters in your file, you'll need to remove them.
Read more »

Labels: , ,