Skip to content

Instantly share code, notes, and snippets.

@justnoise
Created November 14, 2013 19:21
Show Gist options
  • Select an option

  • Save justnoise/7472716 to your computer and use it in GitHub Desktop.

Select an option

Save justnoise/7472716 to your computer and use it in GitHub Desktop.
Sometimes repeatedly grepping through huge logs is time consuming. If you're targeting a specific period in time, just grab that period and dump it to a pruned log file.
filename=access_log.log
output_filename=${filename}_pruned
start_pattern='2013:13:'
end_pattern='2013:16:30:'
start=`grep -n -m1 "$start_pattern" $filename | cut -f1 -d:`
end=`grep -n -m1 "$end_pattern" $filename | cut -f1 -d:`
sed -n "$start,${end}p" $filename > $output_filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment