Find Line in Files with Grep
Probably one of them no brainers for a lot of people, but
grep
is pretty good at what it
does. Finding text in files. Given the right options, you can easily use it to
find what you need in big batch of source files. An example.
$ grep -RIn 'get(bool' src/
src/guiengine/widgets/label_widget.hpp:55: LabelWidget(bool title=false, bool bright=false);
src/guiengine/widgets/label_widget.cpp:39:LabelWidget::LabelWidget(bool title, bool bright) : Widget(WTYPE_LABEL)
src/io/xml_node.cpp:363:} // get(bool)
Now if you’ve also set --color=auto
(always handy and definitely part of my
.bashrc), then the different parts will
get different colours which makes it even quicker to parse out the good stuff
in your head. Ignoring that, as you can see you get the file the text was found
in as well as the line number it was found at. What more do you need? For
completeness, let me quote the man
pages about what every option does.
-I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
-n, --line-number
Prefix each line of output with the 1-based line number within its input file. (-n is specified by POSIX.)