In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to deal with ^ M in the text file content under Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
When a file written on Windows is opened under Linux or Unix, there will be more characters like ^ M on each line. This is because the newline characters of Windows and * nix are different. Let's see if the file format is different.
View the file format under Linux:
# file filename
# 20140304110001.csv: ISO-8859 text / / without ^ M
# 20140304110002.csv: ISO-8859 text, with CRLF line terminators / / with ^ M
Files processed under Windows have a CRLF line Terminator.
There are several ways to deal with it:
1. Enter in vi command line mode
:% s / ^ M $/ / g # remove ^ M from the end of the line.
:% s / ^ M / / g # remove all ^ M.
:% s / ^ M / [ctrl-v] + [enter] / g # replace ^ M with enter.
:% s / ^ M /\ rcompg # replace ^ M with carriage return.
two。 Use the sed command. The usage is similar to vi:
# sed-e's / ^ M /\ n/g'filename
3. Use the command
Using the dos2unix command, general * nix releases come with this gadget, that is, Windows-* nix file conversion.
Format: dos2unix filename
Convert multiple files
Format: dos2unix file1 file2 file3... .
The above conversion of the file will modify the original file, using the-k parameter, or the-n parameter can not change the file properties.
Format: dos2unix-n oldfile newfile / / create a new file and keep the source file unchanged
Format: dos2unix-k filename / / keep the file timestamp unchanged
The same tool provides * nix-windows file format conversion command: unix2dos, with the same parameters as dos2unix.
* Note: "^ M", you need to type using Ctrl + V + Ctrl + M instead of the ^ + letter M above the number 6.
Thank you for reading this article carefully. I hope the article "how to deal with ^ M in text files under Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.