“Number” Manipulation in Grep

November 7th, 2006 liewsheng Posted in grep, Text Manipulation | Hits: 31426 | 8 Comments »

“grep” will able to display the lines match with keyword or non-keyword (using option “-v”), but you may want to continue to display another few lines after/before the matched keyword:

grep -A N "keyword" filename

this will continue display N lines after the matching line. To display the N lines before matching line :

grep -B N "keyword" filename

Using the file form previous examples (Exclusive Grep), output of command below:

grep -A 3 "ates" filename

will be:

ates, 953645
btest 452345
#testing , this wrong code
#testing , this wrong code

What if you want to display 3 lines before the matching “keyword”:

grep -B 3 "ates" filename

you will get this:

testing 3456
testing, 452345
testing, 652345
ates, 953645

the next thing you may want to find out is the line number where the keyword match:

grep -n "atest" filename

this will be display:

6:ates, 953645

the “6” is the line number where the “keyword” matched.

8 Responses to ““Number” Manipulation in Grep”

  1. I like the helpful information you provide on your articles.

    I will bookmark your blog and check again
    right here frequently. I’m slightly certain I’ll be informed plenty of new stuff proper
    here! Good luck for the next!

  2. Why viewers still make use of to read news papers when in this technological world everything is available on net?

  3. Good day! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any suggestions?

    Feel free to surf to my website telecharger teamviewer (telecharger-teamviewer.blogspot.com)

  4. After looking into a number of the blog articles on your blog, I honestly like your technique of writing a
    blog. I added it to my bookmark site list and
    will be checking back in the near future. Please check out my web site as well and let me
    know your opinion.

  5. What’s Happening i am new to this, I stumbled upon
    this I have found It positively useful and it has
    aided me out loads. I’m hoping to give a contribution & aid other users like its aided
    me. Great job.

  6. Appreciation to my father who told me concerning this web site, this webpage is really amazing.

    Here is my web site; can you escape cheats

  7. Create themes, latest videos and free themes. There are alternatives such as” Scrabble and Wheel of Fortune, to blitz brigade hack make sure that you would like to play, download mobile games are available in the next five years. Brands are eager to try out as it is not necessary that every person who are fonder of speed and thrill which attracts the gamers can play mobile games to suit everyone and anyone. This game is played with much better gaming experience than DirectX 9 will revealintegrated features in nature.

    Look at my homepage – blitz brigade cheats on mac

  8. Can you help them do that, other cars running on the mobile angry birds friends cheats and its application use.
    Some even argue thatMicrosoft DirectX 10. You will find it for a Good Wordsmithing TimeThe
    Best iPad Word Games Ever! This precious pearl will be
    some deletions for the assistance of highly proficient team fro undertaking your development process.
    You can angry birds friends cheats also make it possible for game lovers.

    My web blog: Angry birds friends cheats

Leave a Reply