In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to read standard input from AWK. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
In the awk series, we will see several examples where you can filter the output of other commands instead of reading input from a file as input to awk. Let's start with the dir command, which is similar to the ls command.
In the first example, we use the output of the dir-l command as the input to the awk command so that we can print out the user name of the file owner, the group name to which he or she belongs, and the files he or she owns under the current path.
# dir-l | awk'{print $3, $4, $9;} 'how does AWK read standard input (STDIN) AWK reads standard input (STDIN)
List the user files under the current path
Looking at another example, we use awk expressions, where we want to use an expression in the awk command to filter out strings to print out files that belong to the root user. The command is as follows:
# dir-l | awk'$3pm = "root" {print $1 AWK how to read standard input (STDIN) how to read standard input (STDIN)
List files for root users
The above command contains (= =) for comparison, which helps us filter out the files of root users under the current path. This is done by using the expression $3 percent = "root".
Let's look at another example, where we use an awk comparison operator to match a certain string.
Here, we use the cat command to browse the contents of the file named tecmint_deals.txt, and we want to see only the part with the string Tech, so we will run the following command:
# cat tecmint_deals.txt# cat tecmint_deals.txt | awk'$4 ~ / tech/ {print}'# cat tecmint_deals.txt | awk'$4 ~ / Tech/ {print} 'how does AWK read standard input (STDIN) AWK reads standard input (STDIN)
Match strings with Awk comparison operators
In the above example, we have used the comparison operation with the parameter ~ / matching character /, but the above two commands show us some very important issues.
There is no output from the terminal when you run a command with a tech string, because there is no such string as tech in the file, but run a command with a Tech string and you get output containing Tech.
So you should always pay attention to this problem when doing this kind of comparison, as we saw above, awk is very case-sensitive.
You can always use the output of another command as input to the awk command instead of reading input from a file, which is as simple as we saw above.
This is the end of this article on "how to read standard input in AWK". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it out for more people to see.
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.