I am trying to parse some nginx logs by date. I have written an awk oneliner to find all matching logs for a day, like:
awk '/05\/May\/2012/ { print $0;}' /var/log/nginx/access.log
What I want to do is to loop over some days and months using bash. Here is what I have got
#!/bin/bash
for h in 2012
do
for i in Apr May
do
for j in 01 02 03 04 05
do
echo "/${j}\/${i}\/${h}/"
search_string="'/${j}\/${i}\/${h}/ { print \$0;}'"
echo $search_string;
awk $search_string /var/log/nginx/access.log
echo "${h} ${i} ${j} done"
done
done
done
However, this fails on awk line with:
awk: 1: unexpected character '''
It seems like I need to escape some variables, but I haven’t found a solution so far.
Single quotes are not needed.
Double quotes are needed.