shell 过滤出IP help

zzfeng2012 2015-08-26 04:00:35
cat 111.txt

10.10.22.23 | success | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 4.5G 15G 24% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/vdb 99G 69G 25G 74% /data

10.10.22.24 | success | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 2.5G 17G 14% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/vdb 99G 34G 61G 36% /data

10.10.22.25 | success | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 6.0G 13G 32% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/vdb 99G 20G 75G 21% /data

10.10.22.26 | success | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 1.8G 17G 10% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/xvdb1 99G 6.7G 87G 8% /data




假设111.txt 文件内容是上面所示,怎么将 /data 使用量超过70%的 对应的IP 过滤出来???
...全文
127 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzfeng2012 2015-08-26
  • 打赏
  • 举报
回复
引用 3 楼 lee244868149 的回复:
#!/bin/sh echo -n "" >3.txt cat 1.txt | sed 's/^$/##/g' | xargs | sed 's/##/\n/g' > 2.txt cat 2.txt | grep -onE "[0-9]*% /data" | while read line do percent=$(echo $line | sed "s/.*:\(.*\)%.*/\1/g") if [ $percent -gt 70 ];then index=$(echo $line | sed "s/^\(.*\):.*/\1/g") sed -n "${index}p" 2.txt| awk -F"|" '{print $1}' >> 3.txt echo $percent >> 3.txt fi done
谢谢,效果实现了, 我在你的脚本上 sed -n "${index}p" 2.txt| awk -F"|" '{print $1}' >> 3.txt 这行修改成 sed -n "${index}p" 2.txt | awk '{print $1,print $30}' >> 3.txt 效果也实现了。 非常感谢。
奔跑的路 2015-08-26
  • 打赏
  • 举报
回复
#!/bin/sh echo -n "" >3.txt cat 1.txt | sed 's/^$/##/g' | xargs | sed 's/##/\n/g' > 2.txt cat 2.txt | grep -onE "[0-9]*% /data" | while read line do percent=$(echo $line | sed "s/.*:\(.*\)%.*/\1/g") if [ $percent -gt 70 ];then index=$(echo $line | sed "s/^\(.*\):.*/\1/g") sed -n "${index}p" 2.txt| awk -F"|" '{print $1}' >> 3.txt echo $percent >> 3.txt fi done
zzfeng2012 2015-08-26
  • 打赏
  • 举报
回复
引用 1 楼 lee244868149 的回复:
随便写的可能不够严密,自己调试一下,结果在3.txt中

       #!/bin/sh
       echo -n  "" >3.txt
       cat 1.txt | sed 's/^$/##/g' | xargs | sed 's/##/\n/g'  > 2.txt
       cat 2.txt | grep -onE "[0-9]*% /data" | while read line
       do
               percent=$(echo $line | sed "s/.*:\(.*\)%.*/\1/g")
               if [ $percent -gt 70 ];then
                       index=$(echo $line | sed "s/^\(.*\):.*/\1/g")
                      sed -n "${index}p" 2.txt| awk -F"|" '{print $1}'  >> 3.txt
              fi      
      done 
谢谢,试了这个脚本,可行。 除了显示对应的IP外,我还想让它显示超过70%的/data的使用量, 也就是显示/data超过70%的对应IP和/data已经使用的百分比 怎么实现? 我的问题一开始没描述完整,非常抱歉。
奔跑的路 2015-08-26
  • 打赏
  • 举报
回复
随便写的可能不够严密,自己调试一下,结果在3.txt中

       #!/bin/sh
       echo -n  "" >3.txt
       cat 1.txt | sed 's/^$/##/g' | xargs | sed 's/##/\n/g'  > 2.txt
       cat 2.txt | grep -onE "[0-9]*% /data" | while read line
       do
               percent=$(echo $line | sed "s/.*:\(.*\)%.*/\1/g")
               if [ $percent -gt 70 ];then
                       index=$(echo $line | sed "s/^\(.*\):.*/\1/g")
                      sed -n "${index}p" 2.txt| awk -F"|" '{print $1}'  >> 3.txt
              fi      
      done 

18,772

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 专题技术讨论区
社区管理员
  • 专题技术讨论区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧