ShellでHTTPRequestログを精査 2
ShellでHTTPRequestログを精査 1 - xai1981's blog
上記の続き~ って事でお次は、正規表現を使って、欲しい情報かどうか判断します。
1行ずつ読み込んで正規表現で判断するスクリプト
[root@kabosu ~]$ cat readline_one_expr.sh #!/bin/sh filename=$1 cat ${filename} | while read line do echo ${line} if expr "${line}" : ".*[A-Za-z].*"; then echo "hit" fi done
テスト用の読み込みテキストデータ
[root@kabosu ~]$ cat data.txt 0000000000000000000 aaaaaaaaaaaaaaaaaaa 2222222222222222222 bbbbbbbbbbbbbbbbbbb 4444444444444444444 ccccccccccccccccccc 6666666666666666666 ddddddddddddddddddd 8888888888888888888 eeeeeeeeeeeeeeeeeee
実行結果
[root@kabosu ~]$ ./readline_one_expr.sh data.txt 0000000000000000000 0 aaaaaaaaaaaaaaaaaaa 19 hit 2222222222222222222 0 bbbbbbbbbbbbbbbbbbb 19 hit 4444444444444444444 0 ccccccccccccccccccc 19 hit 6666666666666666666 0 ddddddddddddddddddd 19 hit 8888888888888888888 0 eeeeeeeeeeeeeeeeeee 19 hit
ヒットした行は hit と表示しています。何か数字が出てるのが気になるけど、とりあえずやりたい事が出来ました ^^