nomike

Freitag, August 12, 2005

Regular Expressions for Matching Apache Logfile-Entrys

I'm currently developing a shell script which analyses a customer website and unfies it to a new format (dirs, filenames, etc.) for beeing put on our new Server. Part of this script is an Access-Log format recognition function. Therfore I created two sed scripts.

Common Log Format:
sed "s/^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} - [a-z,A-Z,0-9,\\,,\\_, ,\\-]* \[[0-9]\{1,2\}\/[a-z,A-Z]\{1,4\}\/[0-9]\{4\}:[0-9]\{1,2\}:[0-9]\{1,2\}:[0-9]\{1,2\} [+,-][0-9]\{4\}\] \"[^\"]*\" [0-9]\{3\} [0-9,-]*$/#/"

Cobined Log Format:
sed "s/^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} - [a-z,A-Z,0-9,\\,,\\_, ,\\-]* \[[0-9]\{1,2\}\/[a-z,A-Z]\{1,4\}\/[0-9]\{4\}:[0-9]\{1,2\}:[0-9]\{1,2\}:[0-9]\{1,2\} [+,-][0-9]\{4\}\] \"[^\"]*\" [0-9]\{3\} [0-9,-]* \"[^\"]*\" \"[^\"]*\"$/#/"

Feel free to use this, and send me suggestions for improvement/error corrections/etc.

1 Comments:

Kommentar veröffentlichen

<< Home