简体   繁体   English

Bash,将结果 awk '{print $1} 与某物进行比较,如果为真则返回 awk '{print$2}

[英]Bash, compare the a result awk '{print $1} with something and return awk '{print$2} if true

My File Looks like this:我的文件看起来像这样:

    790 45.61.188.53
    494 45.61.188.95

I need to compare the first one for example 790 with something else and then print the second one.我需要将第一个(例如 790)与其他内容进行比较,然后打印第二个。

So my code actually look like this:所以我的代码实际上是这样的:

c=$(cat $IPS | sed '/^$/d' | sort -rn | uniq -c | sort -rn | awk '{print $1}' | head -5 >> $CFILE)
i=$(cat $IPS | sed '/^$/d' | sort -rn | uniq -c | sort -rn | awk '{print $2}' |head -5)


for count in `cat $CFILE`
do
    if (( $count > 100 ));then
        echo "$i"
    fi
done

But the return output is :但返回输出是:

45.61.188.53
45.61.188.95
20.230.214.19
45.61.187.215
78.142.63.3
45.61.188.53
45.61.188.95
20.230.214.19
45.61.187.215
78.142.63.3
45.61.188.53
45.61.188.95
20.230.214.19
45.61.187.215
78.142.63.3
45.61.188.53
45.61.188.95
20.230.214.19
45.61.187.215
78.142.63.3

and so on

I assume that this is normal behavior for the for loop but I cannot understand how can I do it using something different.我认为这是 for 循环的正常行为,但我不明白如何使用不同的方法来做到这一点。 Maybe arrays would be useful ?也许数组会有用?

您可以完全在awk中执行此操作

awk '$1 > 100 { print $2 }' "$CFILE"
{m,g}awk '$!NF = $(NF *= 100<+$_)'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM