Skip to content

Instantly share code, notes, and snippets.

@brokendish
Created February 11, 2012 13:10
Show Gist options
  • Save brokendish/1799354 to your computer and use it in GitHub Desktop.
Save brokendish/1799354 to your computer and use it in GitHub Desktop.
順番に説明とかしてみる
①grep 'ABC' /home/hoge/apache404log.txt |
②awk '{print $1}' |
③sort |
④uniq |
⑤xargs -I{} whois {} |
⑥grep -i country |
⑦sed 's/ //g' |
⑧sort |
⑨uniq
⑩>ABC_country.txt
@brokendish
Copy link
Author

①「apache404log.txt」テキストファイルから「ABC」の文字がある行だけを抜き出す
②awk(※1)というコマンド(スクリプト言語)で行の最初の単語(IPアドレス)を抜き出す
③並び替える(昇順)※④で重複行を除く為
④重複行を除く※⑤で不要な処理をさせない為
⑤whoisコマンド(※2)に1行ずつ引数として渡す
⑥whoisコマンドの結果から「country」の文字がある行だけ抜き出す
⑦sedコマンド(※3)で空白文字を削除する
⑧並び替える(昇順)※⑨で重複行を除く為
⑨重複行を除く※⑩で重複した余分なものを出力しない為
⑩ABC_country.txtとして保存する

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment