Skip to main content

Use of variable in bash script making use of awk [Resolved]

I would like to create a script to dynamically call this awk command:

awk '/2019.07.16 09:00/, /2019.07.16 10:00:/' mylog.log | awk '$3 == "-" && $4 != "-" {print $4}' | sort | uniq | wc -l

I'm usually invoking that command successfully but now I want to execute it multiple times changing time ranges, I'm having difficulties in setting times, here follows what I tried:

for counter in {7..7}
    do
        echo "Counter "$counter
        echo /2019.07.16 0"$counter":00/, /2019.07.16 0"$((counter+1))":00:/

        # The commented code shows unsuccessful attempts
        #awk '/2019.07.16 0"$counter":00/, /2019.07.16 "$((counter+1))":00:/' mylog.log | awk '$3 == "-" && $4 != "-" {print $4}' | sort | uniq | wc -l

        # The commented code shows unsuccessful attempts
        #startvar=0"$counter":00/,
        #echo $startvar
        #awk -v start="$startvar" '/2019.07.16 start /2019.07.16 08:00:/' mylog.log | wc -l                 
    done

Have you some hint? Thanks in advance, bye


Question Credit: Gamby
Question Reference
Asked July 18, 2019
Tags: awk
Posted Under: Unix Linux
10 views
1 Answers

Your Answer