- This will give the current time minus 1 min in the form of hh:mm
date +%R -d "-1 min"
This will print the lines begining (line that matches the above hh:mm time) till the end of the line for the file req.txt
sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt
This will count the no of lines returned
wc -l
so
sed -n "/ $(date +\%R -d "-1 min")/,$"p req.txt| wc -l
will o/p no of lines.
- This will print lines between the lines that matches 19:00 and till 22:00
awk '/19:00/,/22:00/' app.log
From the above lines, it will filter only the lines that contain the string mytesturl
awk '/19:00/,/22:00/' app.log |grep "mytesturl"
From the returned lines, this will print field no 1,6 and 10 only which are comma seperated
awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep ',900,'|awk -F, '{print $1, $6, $10}'
This will print only field 2 from the above lines
awk '/19:00/,/22:00/' app.log |grep "mytesturl"|grep ',900,'|awk -F, '{print $1, $6, $10}' | awk '{print $2}'
The sed command and sort and uniq:
sed will look for string like :hh.mmm and replace with nothing and its o/p is sorted and then count on the uniq values