In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use the awk variable $0. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Content of the script:
#! / bin/bash
For ip in `cat ip.lst`
Do
. / ssh.exp $ip > / dev/null 2 & > 1
Done
NK= `awk 'BEGIN {bs=4000000} / access/ {if ($1 > bs) {nk=NR-1;print nk}}' exp.log`
For nnk in $NK
Do
Awk-F "[@ |']" 'NR==' "$nnk"' {print $2} 'exp.log
Done
And then found the ghost of $0 in awk. So it was further simplified to this:
The code is as follows:
#! / bin/bash
For ip in
`cat ip.lst`
Do
. / ssh.exp $ip > / dev/null 2 & > 1
Done
Awk 'BEGIN {bs=4000000} / access/ {if ($1 > bs) print x}; {print $0}' exp.log | awk-F "[@ |']"'{print $2}'
I finally realized my dream of accomplishing it in one sentence. Yeah~ still doesn't quite understand this principle. Because print x _ 0 is the previous line, but print $0 is the line. Why? On the Internet, there is another way to write the line before printing, which makes it even more baffling:
Awk'/ regex/ {print (x = "?": X)}; {x = 0}'$1
After printing, the line looks like this:
Awk'/ regex/ {getline;print}'$1
But after all, this is just up and down, and if you want the first few lines, you still have to rely on NR.
Because of the streaming of awk, the x of print x has to wait until the next line to print.
Thank you for reading! This is the end of the article on "how to use the awk variable $0". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.