tail -f <filename> | grep -C <# of lines to show above and below> <text>

Live filter a log file using grep and show x# of lines above and below


4
By: manalang
2009-02-06 17:19:01

These Might Interest You

  • Filter out lines of input that contain 72, or fewer, characters. "sed -n" : don't print lines by default "/^.\{73,\}/" : find lines that start with 73 (or more) characters "p" : print them Show Sample Output


    0
    sed -n "/^.\{73,\}/p" < /path/to/file
    flatcap · 2014-03-20 12:31:57 0
  • Filter comments and empty lines in files. I find this very useful when trying to find what values are actually set in a very long example config file. I often set an alias for it, like : alias nocomment='grep -v "^\($\|#\)"' Show Sample Output


    2
    grep -v "^\($\|#\)" <filenames>
    raphink · 2009-02-16 21:40:09 1

  • 7
    rtmpdump -v -r rtmp://livestfslivefs.fplive.net/livestfslive-live/ -y "aljazeera_en_veryhigh" -a "aljazeeraflashlive-live" -o -| mplayer -
    ricardoarguello · 2011-03-29 19:33:39 4
  • Filter out lines of input that contain 72, or fewer, characters. This uses bash only. ${#i} is the number of characters in variable i. Show Sample Output


    1
    while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
    flatcap · 2014-03-20 12:27:06 0
  • This command is used to stream a video file as live to some streaming server like Wowza, Red5 . etc


    0
    ffmpeg -re -i localFile.mp4 -c copy -f flv rtmp://server/live/streamName
    unni9946 · 2014-03-07 05:52:11 0
  • ################################################################################ # get all modified files since last commit and zip them to upload to live server ################################################################################ # delete previous tar output file rm mytarfile.tar -rf #rm c:/tarOutput/*.* -rf # get last commit id and store in variable declare RESULT=$(git log --format="%H" | head -n1) # generate file list and export to tar file git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $RESULT | xargs tar -rf mytarfile.tar # extract tar files to specified location tar -xf mytarfile.tar -C c:/tarOutput Show Sample Output


    1
    git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT COMMID_HASH | xargs tar -rf mytarfile.tar
    sarfraznawaz2005 · 2014-03-04 12:16:07 1

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: