Tuesday, July 12, 2016

Using Grep to search for a string inside a file

Simple story here really.

I had a borked config somewhere inside my /etc/ folder that was throwing some application errors. It's a development machine with poor documentation so I had to try to figure out where the typo happened.

Grep is a simple, but incredibly powerful command that took care of this quite easily. The flags I used  provided the filenames that contain the matching string as well as the line number where the string is matched. Helpful for fixing or tweaking some borked config or code.

Usage is quite simple:


grep -inr "badconfigurationstring" /searchdirectory

the flags are as follows;
-i = ignore case sensitivity
-n = print line number of matching string
-r = recursively read all files under search directory

more info at the grep man page: http://linux.die.net/man/1/grep

--end.






4 comments:

  1. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.


    SAP SD Training in Chennai

    ReplyDelete
  2. This command will contribute to the more productive search. This will give the ability to find easily the string of the relevant content.

    ReplyDelete
  3. This was useful. Thank You for adding those materials here, but I think that I'll need help in this case.

    ReplyDelete
  4. The necessary research of the lines becomes simple by the performing uncomplicated action. We only need to enter the correct combination to carry out this action.

    ReplyDelete