In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to remove blank lines from Shell in linux. I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.
1. Grep
$grep-v'^ $'file
-v is used to output mismatched content:
Man grep Matching Control-v,-- invert-match Invert the sense of matching, to select non-matching lines.
The wildcard'^'is used to indicate the beginning of the string and the end of the string.
2. Sed
$sed'/ ^ $/ d'file
Sed, whose full name is "stream editor", or stream editor, is a super utility that uses a simple and compact programming language to parse and transform text.
^ $is used to match blank lines, and d is one of the commands of sed to delete matches:
$man sed COMMAND SYNOPSIS... D Delete pattern space. Start next cycle. ...
3. Awk
$awk'! / ^ $/ 'file
Additional knowledge:
Awk (named after the initials of its founders Alfred Ehou, Peter Weinberg and Brian Collinhan) is a programming language for processing text. It is an excellent text processing tool that scans every line of the file as it works, looking for patterns that match what is given on the command line. If a match is found, proceed to the next programming step. If no match is found, proceed to the next line.
The awk program consists of a series of patterns-action pairs:
Pattern {action}
Back to our requirement, ^ $is used to match blank lines! The default action for awk is print, so we don't even write print.
4. Tr
$cat in.txt | tr-s'\ n'
Tr is an acronym for translate to replace or delete specific characters in the input dataset.
-s is used to compress the sequence of the same adjacent characters in its output into a single character:
$man tr DESCRIPTION-s,-- squeeze-repeats replace each sequence of a repeated character that is listed in the last specified SET, with a single occurrence of that character
5. Vi
$vi file: G / ^ $/ d and above are all the contents of the article "how to remove blank lines in Shell 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.