In large software projects we often want to find out in which source
files a certain variable is defined and/or used. Write a bash
shell script sourcecode that takes three arguments:
the path to a directory
the file extension (the part after the last dot in a file name)
the name of a variable
The script has to look up the text files that contain the given variable. Only files within the given directory (and subdirectories) whose name ends with the given extension must be searched. For every source code line that contains the variable, the script has to write a line to standard output, containing the following three fields (separated by a colon):
the name of the file containing the printed source code line
the line number within the file
the source code line itself
Note: the output must be sorted according to file name (alphabetically, increasing) and in case of equal file name the output must be sorted according to line numbers (increasing).
$ sourcecode /usr/lib py spam
/usr/lib/python2.5/site.py:36:with three subdirectories, foo, bar and spam, a...
/usr/lib/python2.5/site.py:56:because bar.pth comes alphabetically before foo...
/usr/lib/python2.5/cgitb.py:32: return <!--: spam
$ sourcecode /usr/share pl foobar
/usr/share/doc/swig2.0-examples/test-suite/perl5/exception_order_runme.pl:18:...
/usr/share/doc/swig2.0-examples/perl5/multiple_inheritance/runme.pl:15:print ...
/usr/share/doc/swig2.0-examples/perl5/multiple_inheritance/runme.pl:16:$foo_B...