In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to delete the blank lines in the file in the Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The following five ways can be done.
Sed: a stream editor that filters and replaces text.
Grep: outputs the line to which it matches.
Cat: merge the files and print the contents to standard output.
Tr: replace or delete characters.
The awk:awk tool is used to execute programs written in the awk language, specifically for text processing.
Perl:Perl is a programming language for processing text.
I created a 2daygeek.txt file to test these commands. Here are the contents of the file.
$cat 2daygeek.txt2daygeek.com is a best Linux blog to learn Linux. It's FIVE years old blog. This website is maintained by Magesh M, it's licensed under CC BY-NC 4.0. He got two GIRL babys. Her names are Tanisha & Renusha.
Now that everything is in place, we are ready to start verifying it in a variety of ways.
Use the sed command
Sed is a stream editor stream editor. The stream editor is used to edit the text in the input stream (file or pipe).
$sed'/ ^ $/ d' 2daygeek.txt2daygeek.com is a best Linux blog to learn Linux.It's FIVE years old blog.This website is maintained by Magesh M, it's licensed under CC BY-NC 4.0.He got two GIRL babes.Her names are Tanisha & Renusha.
The following are the details of the command deployment:
Sed: the command itself.
/ /: tag matching range.
^: matches the beginning of the string.
$: matches the end of the string.
D: delete the matching string.
2daygeek.txt: source file name.
Use the grep command
Grep can search through files through regular expressions. The expression can be a character separated by one or more lines of blank lines, and grep prints all matches.
$grep. 2daygeek.txtor$ grep-Ev "^ $" 2daygeek.txtor$ grep-v-e'^ $'2daygeek.txt2daygeek.com is a best Linux blog to learn Linux.It's FIVE years old blog.This website is maintained by Magesh M, it's licensed under CC BY-NC 4.0.He got two GIRL babes.Her names are Tanisha & Renusha.
The following are the details of the command deployment:
Grep: the command itself.
Replace any character.
^: matches the beginning of the string.
$: matches the end of the string.
E: use extended regular matching patterns.
E: use regular regular matching patterns.
V: reverse matching.
2daygeek.txt: source file name.
Use the awk command
Awk can execute scripts written in the awk language, mostly dedicated to processing text. An awk script is a combination of a series of awk commands and rules.
$awk NF 2daygeek.txtor$ awk'! / ^ $/ '2daygeek.txtor$ awk' /. / '2daygeek.txt2daygeek.com is a best Linux blog to learn Linux.It's FIVE years old blog.This website is maintained by Magesh M, it's licensed under CC BY-NC 4.0.He got two GIRL babes.Her names are Tanisha & Renusha.
The following are the details of the command deployment:
Awk: the command itself.
/ /: tag matching range.
^: matches the beginning of the string.
$: matches the end of the string.
.: matches any character
!: delete the matching string.
2daygeek.txt: source file name.
Use a combination of cat and tr commands
Cat is the abbreviation for concatenated (spliced) concatenate. It is often used to read the contents of a file in Linux.
Cat is one of the most frequently used commands in Unix-like systems. It provides three common functions for dealing with text files: displaying the contents of the file, splicing multiple files into one, and creating a new file.
Tr can convert, compress, or delete characters from standard input, and then redirect them to standard output.
$cat 2daygeek.txt | tr-s'\ n'2daygeek.com is a best Linux blog to learn Linux.It's FIVE years old blog.This website is maintained by Magesh M, it's licensed under CC BY-NC 4.0.He got two GIRL babes.Her names are Tanisha & Renusha.
The following are the details of the command deployment:
Cat: the cat command itself.
Tr: the tr command itself.
|: pipe symbol. It can use the standard output of the previous command as the standard input of the next command.
S: replace any number of repeating characters in the dataset into one.
\ n: add a new line feed.
2daygeek.txt: source file name.
Use the perl command
Perl represents a useful extraction and reporting language, Practical Extraction and Reporting Language. At the beginning, Perl was designed as a programming language dedicated to text processing, and now it has been extended to many fields such as Linux system management, network programming and website development.
$perl-ne 'print if /\ Splink' 2daygeek.txt2daygeek.com is a best Linux blog to learn Linux.It's FIVE years old blog.This website is maintained by Magesh M, it's licensed under CC BY-NC 4.0.He got two GIRL babes.Her names are Tanisha & Renusha.
The following are the details of the command deployment:
Perl: perl command.
N: read the data line by line.
E: execute a command.
Print: print information.
If: if conditional branch.
/ /: tag matching range.
\ s: matches any non-white space character.
2daygeek.txt: source file name.
This is the end of the introduction of "how to delete blank lines in a file in the Linux system". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.