grep # ALL HAIL. Should know these:
grep -F # fixed/literal mode, use to search exactly what you type, no regex
grep -i # case insensitive
grep -v # reverse, shows only lines that do NOT match
grep -w # matches on "words" only, grep -w "lag" won't match "flag"
sort # usually combine with uniq
uniq # usually combined with sort
wc -l # count lines
head -n 10 # top 10! you won't believe number 7!
tail -f # tail with follow, useful for log that are being updated, such as:
tail -f | grep -i error
cut # to only get certain columns, for example:
cut -d' ' -f12-15 # split on spaces, only show columns 12 through 15
# or use gawk when dealing with buffers
gawk '{$12,$13,$14,$15}'
Here's a real command I'm using in a demo in 5 minutes to show something that's hidden deep in our logs:
EDIT: Unfortunately that doesn't work because of file buffering. Here's an actual working command for a log that is getting updated in live, but it does effectively the same thing:
The most common pipes I use are:
Here's a
realcommand I'm using in a demo in 5 minutes to show something that's hidden deep in our logs:EDIT: Unfortunately that doesn't work because of file buffering. Here's an actual working command for a log that is getting updated in live, but it does effectively the same thing:
Bonus: Here's a super evil one >:)
Cheers for the tip about grep options. I do a lot of grepping, but I think those options will save me heaps of time in the future.
sort -u to optimize sort | uniq ;)
Unless you need to count the unique results: blah | sort -n | uniq -c