Last active
May 16, 2018 10:17
-
-
Save greymd/1c730989e4836bf4254abe11829a21a5 to your computer and use it in GitHub Desktop.
Convert app.log to csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sed '/response:/{:loop;N;/<\/root>/!b loop;s/\n//g}' app.log | \ | |
# 特定の時間帯のログだけをgrep | |
grep '^2017-05-09 20:5[0-9]' | \ | |
# あとはgrepなりsedなりawkなりで自由に抽出 | |
grep -oP '<record> *\K.*?(?= *</record>)' | sed 's/<\/[^>]*> *<[^>]*>/,/g;s/<[^>]*>//g' | |
# 同じディレクトリにapp.logを置いて実行 | |
# $ bash script.sh | |
# 出力結果: | |
# A001,1990-01-04,0 | |
# A002,2017-04-01,1 | |
# A003,1995-03-20,0 | |
# A004,2000-02-20,0 | |
# A005,2001-12-20,1 | |
# A006,2010-02-01,0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment