- Under Linux, it is unavoidable to use vim to open some edited text files under Windows. We will find a ^m symbol at the end of each line of the file, because the DOS editor and the Linux editor are inconsistent with the carriage return at the end of the file line.
- For a carriage return definition:
- windows:0d0a
- unix\linux:0a
- mac:0d
- There are several ways to remove these symbols more quickly:
- (1) is the command with VI:
- Open a text file with VI
- VI Dos.txt
- Command mode input
- : Set Fileformat=unix
- : W
- (2) VI using regular expressions to replace
- g/\^m/s/\^m//
- Or
- %s/^m//g
- (3) using the SED tool
- Sed ' s/^m//' filename > Tmp_filename
- (4) Since the window of the carriage return more than ' \ R ', then of course, by deleting ' \ R ', can also be achieved:
- Tr-d ' \ r '
- (5) The last method is my most commonly used method, personally feel most convenient
- Under the Terminal Knock Command:
- $ Dos2unix filename
- switch directly to UNIX format and it's OK! ~
How does Linux get rid of ^m