bash脚本,以输送至while循环之前,输入文件排序 [英] Bash script to sort input file before piping to while loop

查看:108
本文介绍了bash脚本,以输送至while循环之前,输入文件排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的bash脚本:

I have this bash script:

while IFS='"' read -r a ip c
do
    echo "ip: $ip"
    whois "$ip" | grep netname
done < <(head -10 file.log)

我如何排序 file.log 文件(例如,使用排序-n -r )之前的第一个十行被采取并移交给while循环?

How can I sort the file.log file (e.g. with sort -n -r) before the first ten lines are taken and handed over to the while-loop?

推荐答案

如果你想获得排序后的前10行,只是排序,用前

If you want to get the top 10 lines after sorting, just sort it before using head:

while IFS='"' read -r a ip c
do
    echo "ip: $ip"
    whois "$ip" | grep netname
done < <(sort file.log | head -10)
         ^^^^^^^^^^^^^^^

应用,当然您需​​要的排序标记。

这篇关于bash脚本,以输送至while循环之前,输入文件排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆