Hunter的大杂烩 技术学习笔记

2025-04-29

linux下命令行通过管道连接while循环处理

Filed under: 技术话题 — hunter @ 10:23 pm

比如用awk 处理netstat 返回的IP地址,为了去掉地址中的端口号,可以用如下命令:

netstat -anpt |grep EST|awk ‘{print $5}’ |while read addr; do echo $addr|awk -F’:’ ‘{print $1}’; done

先打印 “IP:端口”,然后管道重定向给while,循环读取行数据,再一行行输出给awk进行二次处理

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress