Finding text around a keyword in linux files using grep
Grep, Linux September 9, 2014 , by Mark Walker No Comments on Finding text around a keyword in linux files using grepWhen searching log files grep is an extremely useful tool and one any linux administrator should know.
However the default output will normally be the matching line.
With certain files, for example an SQL export of a database one line could be many thousands or millions of characters long.
In these instances you need a method of extracting just the text surrounding the keyword.
grep -E -o ".{0,5}keyword.{0,5}" file.sql
The {0,5} before and after the keyword specifies it will display 5 characters before and 5 characters after.
Play with these numbers to meet your requirements but keep them as small as possible when dealing with huge files since higher numbers will take up a lot more processing grunt.
Founder at Awcode
Mark Walker is a web developer, system administrator and entrepreneur, born in England but calling Thailand home for over a decade.
Latest posts by Mark Walker (see all)
- The Quintessence of Cybersecurity and Stellar IT Support - November 9, 2023
- Choosing the Right Payment Processor for Your Website - March 3, 2022
- Choosing a business management system - June 11, 2020
Related Articles
-
-
Why Does Everybody Love Docker?
November 28, 2014
-
Clearing postfix mail queue by domain
September 9, 2014 -
Linux disk full errors but disk has space
September 9, 2014
Latest Reports
-
1 Upgrading to WordPress 4.5
May 5, 2016 -
2 WordPress Plugins
January 26, 2016 -
3 What Are CMS Platforms And How Do You Choose The Right One?
November 19, 2014 -
4 How To Create A Successful Website On A Budget
November 18, 2014
-
1 Choosing the Right Payment Processor for Your Website
March 3, 2022 -
2 How To Write An Excellent Product Review
December 26, 2014 -
3 Fantastic Web Design Tips That Will Help Improve Your Site
December 15, 2014 -
4 Tips You Need To Know About Web Hosting
November 26, 2014 -
5 The Biggest Websites In The World Today
November 23, 2014
-
1 Fantastic Web Design Tips That Will Help Improve Your Site
December 15, 2014 -
2 A Review Of 3 Web Design Software Packages For Beginners
December 5, 2014 -
3 Four Fantastic Tips For Web Development
November 24, 2014 -
4 What Are CMS Platforms And How Do You Choose The Right One?
November 19, 2014 -
5 How To Create A Successful Website On A Budget
November 18, 2014
-
1 Why Does Everybody Love Docker?
November 28, 2014 -
2 Tips You Need To Know About Web Hosting
November 26, 2014 -
3 Clearing postfix mail queue by domain
September 9, 2014 -
4 Linux disk full errors but disk has space
September 9, 2014
Leave a comment
You must be logged in to post a comment.