In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how linux shell converts multi-line files into one line, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Linux shell converts multiline files to one line
1. Adopt awk
Awk BEGIN {RS=EOF}'{gsub (/\ nAccord, "); print} 'file
Note: awk sets the record separator (record separator, that is, RS) to\ n by default. This line of code sets RS to EOF (end of file), that is, regards the file as a record, and then replaces\ nwith spaces through the gsub function, and finally outputs.
two。 Adopt sed
Sed': a; Numbai /; t a; 'file
Note: sed is processed by default only by line, N can read it into the next line, and then replace\ n, so that you can combine two lines with one line. But how do you put all the lines together? The jump function of sed can be used. : a set a tag an at the beginning of the code, use the jump command t a to jump back to the label an at the end of the code execution, and re-execute the code, so that all lines can be merged into one line recursively.
3. Cat file | xargs
This manual page documents the GNU version of xargs. Xargs reads argu-
Ments from the standard input, delimited by blanks (which can be pro-
Tected with double or single quotes or a backslash) or newlines
The above is the description of xargs in the man manual. In fact, xargs is an extension of the shell command line parameter limit.
The meaning of this command is also very simple, passing the contents of file as parameters to the X program.
If you use echo as the X program, the command is:
Cat file | xargs echo
This command is consistent with the cat file | xargs behavior, because the default behavior of xargs is printout.
4. Yong tr replaces the last'\ n' as','
Cat 2232_1.txt | tr'\ n','
Thank you for reading this article carefully. I hope the article "linux shell how to convert multiple lines of documents into one line" 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.