2014-07-02 47 views
0

我想知道是否有人能告訴我一個很好的方法來清理awk,grep,cut等這個txt文件。?最優雅的方式。我設法擺脫了相當多的垃圾(文件比這大得多),但我沒有喜悅擺脫「/」並將它們添加到一個新的單獨的行。最好用bash清理輸出文件是什麼?

這是我attemped代碼

cat nmap_results |grep [A-Za-z0-9] |sort -u > New_results.txt 

這裏行是結果:

Host: 192.168.15.201() Ports: 21/closed/tcp//ftp///, 22/closed/tcp//ssh///, 23/closed/tcp//telnet///, 25/closed/tcp//smtp///, 80/closed/tcp//http///, 110/closed/tcp//pop3///, 139/open/tcp//netbios-ssn///, 443/closed/tcp//https///, 445/open/tcp//microsoft-ds///, 3389/closed/tcp//ms-wbt-server/// 
Host: 192.168.15.201() Status: Up 
Host: 192.168.15.202() Ports: 21/closed/tcp//ftp///, 22/filtered/tcp//ssh///, 23/closed/tcp//telnet///, 25/filtered/tcp//smtp///, 80/open/tcp//http///, 110/closed/tcp//pop3///, 139/closed/tcp//netbios-ssn///, 443/filtered/tcp//https///, 445/filtered/tcp//microsoft-ds///, 3389/closed/tcp//ms-wbt-server/// 
Host: 192.168.15.202() Status: Up 
Host: 192.168.15.205() Ports: 21/open/tcp//ftp///, 22/closed/tcp//ssh///, 23/closed/tcp//telnet///, 25/closed/tcp//smtp///, 80/open/tcp//http///, 110/closed/tcp//pop3///, 139/open/tcp//netbios-ssn///, 443/open/tcp//https///, 445/open/tcp//microsoft-ds///, 3389/open/tcp//ms-wbt-server/// 
Host: 192.168.15.205() Status: Up 

感謝WEZ

+3

1.顯示您的嘗試。 2.顯示您的預期輸出。 – anubhava

回答

0

你可以替換逗號的換行,並用空格代替forwardslashes 。 結果更可讀;

$ sed 's/,/\n/g' logfile.txt | sed 's/\// /g' 
Host: 192.168.15.201() Ports: 21 closed tcp ftp 
22 closed tcp ssh 
23 closed tcp telnet 
25 closed tcp smtp 
80 closed tcp http 
110 closed tcp pop3 
139 open tcp netbios-ssn 
443 closed tcp https 
445 open tcp microsoft-ds 
3389 closed tcp ms-wbt-server Host: 192.168.15.201() Status: Up Host: 192.168.15.202() Ports: 21 closed tcp ftp 
22 filtered tcp ssh 
23 closed tcp telnet 
25 filtered tcp smtp 
80 open tcp http 
110 closed tcp pop3 
139 closed tcp netbios-ssn 
443 filtered tcp https 
445 filtered tcp microsoft-ds 
3389 closed tcp ms-wbt-server Host: 192.168.15.202() Status: Up Host: 192.168.15.205() Ports: 21 open tcp ftp 
22 closed tcp ssh 
23 closed tcp telnet 
25 closed tcp smtp 
80 open tcp http 
110 closed tcp pop3 
139 open tcp netbios-ssn 
443 open tcp https 
445 open tcp microsoft-ds 
3389 open tcp ms-wbt-server Host: 192.168.15.205() Status: Up 
+0

非常棒謝謝你,那很乾淨:) – Wesley