看板 Linux 關於我們 聯絡資訊
大家好, 有一份文件(https://goo.gl/2Vc3Ui): 146460673 PING 10.0.0.6 (10.0.0.6): 56 data bytes 想要把14646067356抓出來, 自己試過下列的regular expression: cat short_measurement_PING.txt | sed -r 's/([0-9]+).*PING.*([0-9]+) data bytes/\1 \2/g' cat short_measurement_PING.txt | sed -r 's/([0-9]+)$.*PING.*([0-9]+) data bytes/\1 \2/g' cat short_measurement_PING.txt | sed -r 's/^([0-9]+)$^.*PING.*([0-9]+) data bytes/\1 \2/g' 不過完全沒作用, 想請問大家有什麼建議嗎? 謝謝~ ※ 編輯: decken (212.201.78.21), 06/01/2016 06:10:26
Ice9: 跳行不是要加反斜線? 06/01 08:49
Ice9: 呃,錯了,那是要輸入。 覺得你要在 $ 後面加個\n 06/01 08:53
Ice9: 抱歉。以上都不對~ 06/01 09:46
antontw: 用 awk 來做比較快: 06/01 09:57
antontw: awk '{a=index($0, "P 0) byte=$0;else printf("byte=%d, 06/01 09:57
antontw: data=%d", byte, $4);}' short_measurement_PING.txt 06/01 09:58
antontw: 貼爛了,重貼一次: 06/01 09:59
antontw: awk '{a=index($0, "PING");if (a == 0) 06/01 09:59
antontw: byte=$0; else printf("byte=%d, data=%d", byte, $4);}' 06/01 10:00
antontw: short_measurement_PING.txt 06/01 10:00
Jerr: awk 'NF==1{print $1} $1 ~ /^PING$/ {print $4}' 06/01 15:08
decken: 謝謝大家的建議,總算成功了 06/01 16:33
decken: 原來還有awk這麼好用的工具,,現在才知道 XD 06/01 16:33
Ice9: 嗯,開始學 awk。謝謝~ 06/02 06:43
antontw: Jerr 的比較帥 // 感謝 Jerr 06/02 13:39
pizzahut: 為什麼不直接sed 's///g' XXXX.txt 這樣做就好,比較簡 06/03 15:49
pizzahut: 單,cat xxxx.txt | sed 'g///s' 有點多此一舉 06/03 15:50
pizzahut: 寫錯了 'g///s' 06/03 15:50