Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save laszlomiklosik/a17956506e86058af095 to your computer and use it in GitHub Desktop.
Save laszlomiklosik/a17956506e86058af095 to your computer and use it in GitHub Desktop.
Cropping the relevant section from a log file
# 1) get line number of first relevant log line: (e.g. by date 2014-01-13 13:49)
grep "2014-01-13 13:49" original.log -n | more
# 2) get line number of last relevant log line: (e.g. by date 2014-01-13 16:36)
grep "2014-01-13 16:36" original.log -n | more
# 3) the total number of lines from the original log file:
wc -l original.log -n
# e.g. results of 1-3:
# - from: 2148520
# - to: 3621984
# - length: 3666691
# 4) create the cropped file using a command similar to
# head -n (TO) orig.log | tail -n (TO-FROM)
# in our concrete example:
head -n 3621984 orig.log | tail -n 1473464 > relevant_only.log
# (if you need to use it frequently script all this)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment