In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to delete line breaks in linux". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to delete line breaks in linux".
The newline character in the file needs to be deleted, for example, there is a file a.txt:
1,2,34,5,61,2,34,5,61,2,34,5,61,2,34,5,61,2,34,5,6
1. Use vim to delete newline characters
Vim input command:% s /\ nUnigram g
2. Use the sed command, such as sed': t _ TX _ n _ TX _ s /\ nUniplex _ b _ t 'a.txt
Results: 1Person2, 34, 5, 61, 2, 3, 4, 5, 5, 3, 4, 5, 5, 5, 4, 4, 5, 5, 6
Explain:
: t define label "t" b t go to label "t" to continue to execute N first read a line into the template space of sed, add a newline character (\ n), and then append the next line to the sed template space (then sed performs s /\ nhand replacements on the content in the template space, and displays the replaced content)
3. Use td command, for example:
Cat a.txt | tr'\ n' 1 Magistrate 2 4 pencils 5 6 1 Personals 3 4 pencils 5 pr 6 1 1 pr orgy 3 4 pr é cor 5 pr é cor 6 1 pr é gime 3 4 pencils 5 pence 6 1 pr é gime 2, 4 pencils 5 pence 6 1 pyroria 3 4 pencils 5 pas 6
Note that the last parameter of tr is a space, otherwise an error will be reported.
Delete all newline characters from a file in Linux shell
A small feature that needs to be done is to remove all newline characters from a text file. Generally, you must have thought of using sed to modify it. But I searched it and couldn't find out how to type sed\ nMurray-I know ^ M corresponds to\ r, but it failed and was cut off directly on the command line.
In principle, it can be specified in such a way as\ 015, but I found that it didn't work in practice and had no effect. So in the end, I had to do it by typing the command directly (I haven't verified whether the script works).
Suppose the file to be replaced is called in.txt, and the output file is out.txt:
Sed's / ^ M / / g 'file.txt > tmp.txtsed-I's /\ "/\" / g 'tmp.txtrm-f out.txt; touch out.txtcat tmp.txt | xargs echo-n > > out.txtrm-f tmp.txt
The five steps are:
Convert line breaks in Windows format to UNIX format, that is, delete all\ r characters. Among them, ^ M is not input these two characters directly, but is obtained by holding down Ctrl+V in shell and then typing M.
Escape all double quotes because the subsequent echo needs to use the
Create an empty output file
Delete all\ ncharacters and output the final file
Delete intermediate files
The above is all the content of the article "how to remove newline characters in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.