Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- START_TIME=$1
- END_TIME=$2
- if [ -n "$START_TIME" ]
- then
- STARTED=0
- if [ -n "$END_TIME" ]
- then
- while read LINE
- do
- if [[ ( "$STARTED" = "1" && ! "$LINE" =~ ^[0-9].*$ ) || ( "$LINE" =~ ^[0-9].*$ && "$LINE" > "$START_TIME" && "$LINE" < "$END_TIME" ) ]]
- then
- STARTED=1
- echo "$LINE"
- else
- if [[ "$STARTED" = "1" ]]
- then
- # This prints the line matching the end time
- echo "$LINE"
- fi
- STARTED=0
- fi
- done
- else
- while read LINE
- do
- if [[ ( "$STARTED" = "1" && ! "$LINE" =~ ^[0-9].*$ ) || ( "$LINE" =~ ^[0-9].*$ && "$LINE" > "$START_TIME" ) ]]
- then
- STARTED=1
- echo "$LINE"
- else
- STARTED=0
- fi
- done
- fi
- else
- cat >&2 << EOF
- This script filters log lines between start and (optionally) end times.
- Usage: $0 START_TIME [ END_TIME ]
- Examples: $0 0:00:05 0:00:06
- $0 0:00:05
- EOF
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement