2

I have a big sql dump with long lines and I would like to use grep to find a certain text string.

grep text_string filename.sql

returns the result lines which are huge and difficult to see where my text_string appears. What I want to achieve is to get a result that contains lets say 50 characters to the left and 50 to the right of the search term (text_string). Is this possible?

dasj19
  • 625

1 Answers1

4

Use grep with -o to get the desired portion only:

grep -Eo '.{,50}text_string.{,50}' filename.sql
heemayl
  • 56,300
  • 1
    That only works on lines that DO have 50+ characters on both sides of text_string. Should be grep -Eo '.{0,50}text_string.{0,50}' filename.sql instead. – cas Apr 19 '16 at 11:18
  • @cas oopss..missed that..fixed.. – heemayl Apr 19 '16 at 11:21