Share awk variable $ $ magical _linux shell

Source: Internet
Author: User
Tags ssh

Script content:

Copy Code code as follows:

#!/bin/bash
For IP in ' cat ip.lst '
Todo
./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
Todo
Awk-f "[@| ']" ' nr== ' "$nnk" ' {print $} ' Exp.log
Done

And then found the $ ghost in awk. So it's further simplified into this:

Copy Code code as follows:

#!/bin/bash
For IP in
' Cat Ip.lst '
Todo
./ssh.exp $ip >/dev/null 2&>1
Done
awk ' Begin{bs=4000000}/access/{if ($1>bs) print x}; {x=$0} ' exp.log|awk-f ' [@| '] ' {print $} '

Finally a round of their own with a word to fix its dream. Yeah~ But the principle is still not very clear. Because print x;x=$0 is the previous line, print $ is the bank. Why? Online to print the previous line also put forward another writing, it is more puzzling to see:
awk '/regex/{print (x== "" "": x)}; {x=$0} ' $

And the following line is printed:
awk '/regex/{getline;print} ' $

But this is exactly the right up and down line, if it is to the first few lines, or to rely on NR operation.

Because of the streaming processing of awk, print x;x=$0, this time X will not print until the next line.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.