如何刪除重複的資料???



贊助商連結


bobhsieh
2010-07-07, 05:01 PM
利用ping,並save成一個log file,
想要利用批次檔的方式,
刪除重複資料,並且保留IP資訊,
但是一直試不出來,

不知有何方法,可以做到?

PS: log file 如下:

Reply from 192.168.1.90: bytes=32 time<1ms TTL=127
Reply from 192.168.1.90: bytes=32 time<1ms TTL=127
Reply from 192.168.1.91: bytes=32 time=2ms TTL=127
Reply from 192.168.1.91: bytes=32 time<1ms TTL=127
Reply from 192.168.1.92: bytes=32 time=2ms TTL=127
Reply from 192.168.1.92: bytes=32 time<1ms TTL=127
Reply from 192.168.1.93: bytes=32 time=2ms TTL=127
Reply from 192.168.1.93: bytes=32 time<1ms TTL=127
...

再問一個問題,
可以順便將IP轉換成電腦名稱嗎?

贊助商連結


琥珀
2010-07-08, 10:34 PM
找了一些方法,最後是選擇此腳本處理。使用方法:undup.bat in.txt out.txt。



@echo off > %2

for /f "delims=" %%a in (%1) do (
find "%%a" < %2 > nul
if errorlevel 1 echo %%a >> %2
)


想要更好的結果呈現,可能需要借用 Linux 命令,像是 sort、uniq、awk、sed 這些。此外,還有 vbs 腳本法和網頁處理法,都可以嘗試看看。

bobhsieh
2010-07-09, 02:11 PM
可以再請教一件事嗎...
想要利用nslookup將取得的IP轉換成電腦名稱,
因公司內部的電腦名稱為中文名稱,
因此,利用nslookup解析出來的電腦名稱皆為亂碼,

有無方法解決嗎?

mis339
2010-07-09, 03:43 PM
可以再請教一件事嗎...
想要利用nslookup將取得的IP轉換成電腦名稱,
因公司內部的電腦名稱為中文名稱,
因此,利用nslookup解析出來的電腦名稱皆為亂碼,

有無方法解決嗎?

ping -a IP,試試。

bobhsieh
2010-07-09, 04:12 PM
ping -a IP,試試。



不行耶!!!

bx2aa
2010-07-10, 11:56 PM
利用ping,並save成一個log file,
想要利用批次檔的方式,
刪除重複資料,並且保留IP資訊,
但是一直試不出來,

不知有何方法,可以做到?

PS: log file 如下:

Reply from 192.168.1.90: bytes=32 time<1ms TTL=127
Reply from 192.168.1.90: bytes=32 time<1ms TTL=127
Reply from 192.168.1.91: bytes=32 time=2ms TTL=127
Reply from 192.168.1.91: bytes=32 time<1ms TTL=127
Reply from 192.168.1.92: bytes=32 time=2ms TTL=127
Reply from 192.168.1.92: bytes=32 time<1ms TTL=127
Reply from 192.168.1.93: bytes=32 time=2ms TTL=127
Reply from 192.168.1.93: bytes=32 time<1ms TTL=127
...

再問一個問題,
可以順便將IP轉換成電腦名稱嗎?
================================================
http://sourceforge.net/projects/unxutils/files/
http://sourceforge.net/projects/unxutils/files/unxutils/current/UnxUtils.zip/download

usr\local\wbin\ sed gawk cut wc sleep tail tac uniq sort .........
================================================
nbtstat -a 192.168.0.129 | grep -A1 " ------------------------------
---------------"

然後再去掉 --------------------------- 那行

不過我覺得

當初的 log 應該用 ipscan 直接順便把 IP 和 HOSTNAME 都存檔比較方便

多年前在南京東路五段某號八樓駐點時, 寫過一堆批次檔配合的, 第一步就是 ipscan -s ???.???.???.1 ???.???.???.253 8-floor.txt
在 type 8-floor.txt | grep "^192.168" | gawk "{print $1,$4}"

你的 log file 若用 ipscan 去產生

那就變簡單了

ipscan -s 192.168.1.1 192.168.1.1 temp.txt
type temp.txt | grep "^192.168" | gawk "{print $1,$4}" >> logfile.txt

type logfile.txt | sort | uniq
這行之後產生的列表還能用 wc 計算 logfile.txt 內每個 IP 出現的次數, 和有多少個 IP.

不然以你現在的 log 要先去掉 IP 前後
Reply from 192.168.1.90: bytes=32 time<1ms TTL=127

1. type logfile.txt | sed -e "s/Reply from \(192\.168\.1\..*\):.*/\1/g" | sort | uniq
2. type logfile.txt | gawk "{print $3}" | grep "^192" | sed -e "s/://g" | sort | uniq
在把取得的列表去取 hostname

bobhsieh
2010-07-11, 08:46 PM
感謝您的指教,
透過ipscan and unix utility,
可以順利、簡化工作,

這幾天再把指次檔整理一下,
再上傳上來,
希望造福有這方面困擾的人 ...
;)

bobhsieh
2010-07-12, 10:25 AM
整理一下資料,有需要的人可以參考看看,
PS:
1.用較笨的方法,解決問題,如有可改進的地方,還請大家不吝指教 ^^
2.請準備ipscan210.exe ,版本不用太新,因公司內部使用officescan 10,ipscan太新會認定是有問題的檔案 ... http://sourceforge.net/projects/ipscan/files/ipscan2-binary/
3.Unixutil http://unxutils.sourceforge.net/

ipscan.cmd 內部如下:

@echo off
cls
set log_path=c:\ipscan\ping_log

rem 取得當下的時間(年、月、日)
set /a year=%date:~,4%
set month=%date:~5,2%
set day=%date:~8,2%
set hh=%time:~,2%
set mm=%time:~3,2%
set ss=%time:~6,2%
set mydate=%year%.%month%.%day%-%hh%.%mm%
set mytime=%month%.%day%-%hh%.%mm%
set mydate1=%year%.%month%.%day%
ipscan210 -h -s 172.16.1.1 172.16.1.254 1-%mytime%.1.txt
ipscan210 -h -s 172.16.2.1 172.16.2.254 2-%mytime%.1.txt
ipscan210 -h -s 172.16.3.1 172.16.3.254 3-%mytime%.1.txt
ipscan210 -h -s 172.16.4.1 172.16.4.254 4-%mytime%.1.txt
ipscan210 -h -s 172.16.5.1 172.16.5.254 5-%mytime%.1.txt
ipscan210 -h -s 172.16.6.1 172.16.6.254 6-%mytime%.1.txt
ipscan210 -h -s 172.16.7.1 172.16.7.254 7-%mytime%.1.txt
for %%f in (*.txt) do (type %%f | grep "ms" | gawk "{print $1,$4}" >>%%f.2.txt)
if not exist %log_path%\%mydate1% (mkdir %log_path%\%mydate1%)
move /y *.txt %log_path%\%mydate1%
move /y *.log %log_path%\%mydate1%
pause > nul
@echo off

bx2aa
2010-07-12, 01:34 PM
整理一下資料,有需要的人可以參考看看,
PS:
1.用較笨的方法,解決問題,如有可改進的地方,還請大家不吝指教 ^^
2.請準備ipscan210.exe ,版本不用太新,因公司內部使用officescan 10,ipscan太新會認定是有問題的檔案 ... http://sourceforge.net/projects/ipscan/files/ipscan2-binary/
3.Unixutil http://unxutils.sourceforge.net/

ipscan.cmd 內部如下:

@echo off
cls
set log_path=c:\ipscan\ping_log

rem 取得當下的時間(年、月、日)
set /a year=%date:~,4%
set month=%date:~5,2%
set day=%date:~8,2%
set hh=%time:~,2%
set mm=%time:~3,2%
set ss=%time:~6,2%
set mydate=%year%.%month%.%day%-%hh%.%mm%
set mytime=%month%.%day%-%hh%.%mm%
set mydate1=%year%.%month%.%day%
ipscan210 -h -s 172.16.1.1 172.16.1.254 1-%mytime%.1.txt
ipscan210 -h -s 172.16.2.1 172.16.2.254 2-%mytime%.1.txt
ipscan210 -h -s 172.16.3.1 172.16.3.254 3-%mytime%.1.txt
ipscan210 -h -s 172.16.4.1 172.16.4.254 4-%mytime%.1.txt
ipscan210 -h -s 172.16.5.1 172.16.5.254 5-%mytime%.1.txt
ipscan210 -h -s 172.16.6.1 172.16.6.254 6-%mytime%.1.txt
ipscan210 -h -s 172.16.7.1 172.16.7.254 7-%mytime%.1.txt
for %%f in (*.txt) do (type %%f | grep "ms" | gawk "{print $1,$4}" >>%%f.2.txt)
if not exist %log_path%\%mydate1% (mkdir %log_path%\%mydate1%)
move /y *.txt %log_path%\%mydate1%
move /y *.log %log_path%\%mydate1%
pause > nul
@echo off
個人喜好
set sus=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%

start ipscan210 -h -s 172.16.1.1 172.16.1.254 1-%mytime%.1.txt
start ipscan210 -h -s 172.16.2.1 172.16.2.254 2-%mytime%.1.txt
start ipscan210 -h -s 172.16.3.1 172.16.3.254 3-%mytime%.1.txt
start ipscan210 -h -s 172.16.4.1 172.16.4.254 4-%mytime%.1.txt
start ipscan210 -h -s 172.16.5.1 172.16.5.254 5-%mytime%.1.txt
start ipscan210 -h -s 172.16.6.1 172.16.6.254 6-%mytime%.1.txt
call sleep 10
ipscan210 -h -s 172.16.7.1 172.16.7.254 7-%mytime%.1.txt

10秒是當時環境計算出來的, 確保最後一個不會比其他段提前結束的時間.
請自行測試, 最大應該是 50 秒, 掃一段電腦全部沒開的網段要耗時 50 秒左右.

用 start 的方式像是開花一樣, 先出現一大堆 ipscan 之後開始處理列表, 然後利用這些列表又開花 開一堆命令提示字元視窗, 去掃其他訊息.
最主要的原因是我當時環境有大約 20 段, 一個一個掃會浪費太多時間, 如果繼續增加網段, 不就一天也掃不完, 所以當時就改用開花方式同時掃, 繼續增加網段也沒影響.