gpt4 book ai didi

linux - 如何使用指定的字符串进行 grep 并将值存储在 unix 中

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:37:02 25 4
gpt4 key购买 nike

下面是我的输入文件,

Server:         172.16.249.150
Address: 172.16.249.150#53

Non-authoritative answer:
cloud-us-east.digital-element.net canonical name = usa.cloud.netacuity.com.
usa.cloud.netacuity.com canonical name = us-east.cloud.netacuity.com.
us-east.cloud.netacuity.com canonical name = de-prod-nacs.elasticbeanstalk.com.
de-prod-nacs.elasticbeanstalk.com canonical name = awseb-prod-nacs-397853066.us-east-1.elb.amazonaws.com.
Name: awseb-prod-nacs-397853066.us-east-1.elb.amazonaws.com
Address: 54.243.94.244
Name: awseb-prod-nacs-397853066.us-east-1.elb.amazonaws.com
Address: 54.243.113.63

我想要如下的输出,54.243.94.24454.243.113.63

只有最后两个ip地址,

此外,输入文件将来可能会有所不同,它可能在末尾有很多 ip 地址。所以我需要单独排除第一个 ip。如何实现这个unix?请建议一些命令。提前致谢。

最佳答案

对于给定的输入文件最直接的:

$ grep "Address:" input.txt  | awk -F: '{print $2}' | tail -2
54.243.94.244
54.243.113.63

或者:

$ nslookup cloud-us-east.digital-element.net  | grep "Address:"  | awk -F: '{print $2}' | tail -2

单行,给tr添加一个管道:

$ nslookup cloud-us-east.digital-element.net  | grep "Address:"   | awk -F: '{print $2}' | tail -2 | tr '\012' ' '
54.243.94.244 54.243.113.63

对于“主机”查找:

$ host cloud-us-east.digital-element.net | tr ' ' '\012' | grep -vi "[a-z]"
54.243.113.63
54.243.94.244

编辑:

对于“nslookup”跳过名称服务器:

$ nslookup cloud-us-east.digital-element.net  | grep "Address:" | grep -v "#"  | awk -F: '{print $2}' 
54.243.113.63
54.243.94.244

关于linux - 如何使用指定的字符串进行 grep 并将值存储在 unix 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15916102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com