In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 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 use awk in linux". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "how to use awk in linux".
Awk built-in variables
ARGC command line parameters ARGV command line parameters arrangement ENVIRON support queue system environment variables using FILENAME awk browsed filename FNR browse file number of records FS setting input domain delimiter Equivalent to the command line-F option NF the number of fields of browsing records NR the number of records read OFS output domain delimiter ORS output record separator RS control record separator $0 variable refers to the entire record. $1 represents the first field of the current row, and $2 represents the second field of the current row. and so on. $NF is number finally, which represents the information in the last column, which is different from the variable NF, which counts the total number of each row and column.
Display of commonly used commands
Awk is good at column output
Search / etc/passwd all lines with the root keyword
Awk'/ root/' / etc/passwd
[this is the use of pattern, and only lines that match pattern (in this case root) will execute action (no action specified, default output of each line)]
Search for all lines with the root keyword in / etc/passwd and display the corresponding shell
Awk-F:'/ root/ {print $7}'/ etc/passwd
Statistics / etc/passwd: file name, line number of each line, number of columns per line, corresponding full line content:
Awk-F':'{print "filename:" FILENAME ", linenumber:" NR ", columns:" NF ", linecontent:" $0}'/ etc/passwd
Using printf instead of print can make the code more concise and easy to read
Awk-F:'{printf ("filename:s, linenumber:%3s,column:%3s,content:%3f\ n", FILENAME,NR,NF,$0)}'/ etc/passwd
Print the second line of information for / etc/passwd/
Awk-F: 'NR==2 {print "filename:" FILENAME, $0}' / etc/passwd
Filtering usage of awk
Ls-lF | awk'/ ^ dplink'
Specify a specific delimiter to query the first column
Awk-F ":" {print $1}'/ etc/passwd is all the content of this article "how to use awk 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.