I'm using awk
to output relevant live data from my Apache logs like so:
tail -f access_log | awk '{print $9, $1, $4, $7}';
Works great but it outputs all the images, CSS, etc too. So I'd like to restrict output to only HTML pages. If I use awk '/.html/ {print $9, $1,开发者_C百科 $4, $7}';
it still matches almost all lines in the logfile because the referrer includes ".html". My output doesn't have the referrer though, so is there a way to get awk
to match in my output only, not the input?
Assuming that field 7 contains the URL you're interested in, use
awk '$7 ~ /\.html/ {print <your-field-list>}'
I think the right field number depends on the format of your log file. I could be wrong.
That tells awk to print your field list only if the seventh field matches a literal dot followed by "html".
... | awk '
{
output = $9 OFS $1 OFS $4 OFS $7
if (output ~ /.html/) print output
}'
精彩评论