How to use the awk variable $0
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!