The shell intercepts the specified date of the nginx log print out

  

intercepts the log information between 16/Aug/2010:14:31:30 to 17/Aug/2010:10:12:07 in the access.log and outputs it to Log.txt, my idea, use sed to print 16/Aug/2010: 14:31:30 and 17/Aug/2010:10:12:07 logs and >

#!/Bin/bash

n1=`grep -n '16\\/Aug\\/2010:14:31:30' access.log| Head -1| Cut -d ':' -f1`

n2=`grep -n '17\\/Aug\\/2010:10:12:07' access.log| Tail -1| Cut -d ':' -f 1`

sed -n "${n1},${n2}p" access.log >log.txt

Additional sed The easier way

sed -n '/16\\/Aug\\/2010:14:31:30/, /17\\/Aug\\/2010:10:12:07/'p >log .txt

But this command is correct, but when the access.log has a large number of concurrent access logs at the same time, this is not accurate. The most complete one is still the first one.

Copyright © Windows knowledge All Rights Reserved