Skip to content

Instantly share code, notes, and snippets.

@quickgrid
Created April 1, 2016 03:49
Show Gist options
  • Save quickgrid/bfa0de75d8cff832f7449a51e9af79ad to your computer and use it in GitHub Desktop.
Save quickgrid/bfa0de75d8cff832f7449a51e9af79ad to your computer and use it in GitHub Desktop.
The code below uses regex to read line by line and store the data read in three separate variables. The regular expression print data only for matching time within 8:00 to 10:00
#!/bin/bash
c=0
grep -E -w "8:[0-5][0-9]|9:[0-5][0-9]|10:00?" log.txt | while read ip time city ; do
echo "Logged in at $time with ip $ip and city $city "
c=$(( $c + 1 ))
echo "Found so far: $c"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment