Managing FastAPI Projects with Poetry: A Step-by-Step Guide

When you transfer text files from Windows to Linux or Unix systems, you often see '^M'
characters at the end of lines. This happens because Windows and Linux/Unix handle line breaks differently—Windows uses CR+LF (\r\n
), while Linux/Unix just uses LF (\n
).
In this guide, we’ll look at a few simple ways to remove these characters and explain how each method works.
$ cat -v HelloWorld.java
public class HelloWorld^M
{^M
public static void main(String[] args) {^M
System.out.println("Hello World!");^M
}^M
}^M
The dos2unix
command is a simple and widely used method.
$ dos2unix filename
In Vi/Vim, You can directly search for and remove the '^M'
character. The command above searches for '^M'
at the end of each line throughout the entire file and removes it.
To input '^M', push Ctrl down and then press v and n consecutively.
:%s/^M$//g
sed
is a stream editor, which is a tool that allows you to automatically modify the contents of a file. The above command removes the '^M'
characters from the original file and saves the result to a new file.
^M
must be entered by pressing 'Ctrl + v + m'
, or you can use '\r'
as an alternative.$ sed -e "s/^M//g" org_file > new_file
$ sed 's/\r//g' org_file > new_file
Comments
Post a Comment