Sunday, August 7, 2016

Limiting grep output

Here's a quick way to limit output of the grep command.

Most of the time, we issue the following to find needle in the haystack:

grep needle file.txt

This prints out the matching pattern. If the output is way too long and we only need a section of it, we can use the extended grep (a.k.a. egrep) option.

Here's how to use regular expressions to instruct grep to only display 40 characters before and after the matching pattern:

grep -Eo '.{0,40}needle.{0,40}' file.txt


Shaakshi said...

After looking into a handful of the blog articles on your site, I really like your technique of writing a blog. I book marked it to my bookmark site list and will be checking back in the near future. Take a look at my website as well and let me know your opinion.
Car Wash Services in Mumbai

Philips Huges said...

Wonderful blog.. Thanks for sharing informative Post. Its very useful to me.

Installment loans
Payday loans
Title loans

sandhosh said...

great article which conveyed a good information.awaiting for more updaates like this.
SEO Company in India
SEO Services in India
SEO Companies in India
SEO Company India
SEO Services India

Aashi siva said...

Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us

Vmware Training in Chennai

Web Designing Training in Chennai

AWS Training in Chennai

Linux Training in Chennai

Microsoft Azure Training in Chennai

Chris Topinka said...
This comment has been removed by the author.