如何删除ssh映射中的重复脚本?用python?awk或sed?

只要实现就可以

[root@localhost company]# cat nat.cfg
29003 192.168.5.170:29003
29003 192.168.5.170:29003
29093 192.168.5.169:29093
[root@localhost company]# for i in `cat nat.cfg |awk '{print $2}'`;do grep $i nat.cfg;grep $i nat.cfg|wc -l;done
29003 192.168.5.170:29003
29003 192.168.5.170:29003
2
29003 192.168.5.170:29003
29003 192.168.5.170:29003
2
29093 192.168.5.169:29093
1

-------------------------------------------------

[root@localhost company]# cat chuli.py
import os
cmd = "for i in `cat nat.cfg |awk '{print $2}'`;do grep $i nat.cfg|wc -l;done"
num_cmd = os.popen(cmd)
while True:
    i = num_cmd.readline().strip()
    if i == '':
        break
    else:
        if i >1:
            print 'need delete %s'%i
        else:
            pass

[root@localhost company]# python chuli.py
need delete 2
need delete 2
need delete 1

 

相关文章:

  • 2022-12-23
  • 2022-02-17
  • 2021-07-06
  • 2021-11-29
  • 2021-06-26
  • 2022-12-23
猜你喜欢
  • 2021-04-03
  • 2021-07-20
  • 2021-06-25
  • 2021-12-28
  • 2021-07-13
  • 2022-12-23
相关资源
相似解决方案