So since Feb this year, i have been assigned on a new project at work. This new project involves working with a variety of independent sub-projects for this client and the sheer variety of the sub-projects can sometimes be overwhelming. What has happened a few times is that, the client starts a new sub-project, hands it to us and says we need this application to do “X”. Can you make it do that? So the task is assigned to me and I have a project with no documentation, no instructions but I need to get on with it and solve the issue as soon as I can. In this post, I will talk about the tools I use that make it easier for me in getting to know a new programming project.

So how do i approach this? Since i work on a mac,  which basically has the very awesome terminal that amongst others, has this useful tool called grep. 

A new programming project

How do i use it for my needs?  well say i have an AngularJS project, stored in a folder projFolder, and i have no prior knowledge of how it is structured and i have to figure out why a controller does not navigate to route blog after a certain function call. So firstly i need to figure out where the word blog is used in the project. The best thing to do here is to go through all the files of the project and find out every line where the word blog appears.  This can be achieved as follows,

Open the terminal and navigate to projFolder i.e. cd projFolder

Search through all the files in that folder that have the word blog, in them via

grep -nr “blog” projFolder/

That command will show up a bunch of results, which will show So what are -nr?

  • -n: show the line numbers in the search results
  • r: recursively search through all the sub-directories of the folder being searched in, which in this case is projFolder
  • -nr: If we want to use both -n and -r for the same search, we can just chain them together i.e. –nr instead of doing -n -r.
Say projFolder contains a certain file i.e. global.min.js that i wanted to ignore in my search,  ok lets do that then
grep -nr “blog” –exclude=global.min.js projFolder/
The –exclude option does exactly what you would expect to do, ignore the files while doing the search. Ok so what if i want to exclude both global.min.js and all html files?

grep -nr “blog” –exclude={global.min.js,*.html} projFolder/

It is actually quite simple, we can just write the search results to another file. The files or a group of files to be ignored can be added in the {} operator would ensure those files are not looked at while searching through the files. The conditions to ignore must be separated by a comma (,) and you must make sure that there is not space before or after the comma.  Now lastly, say my search returns lots of results and i wish to analyse the results in a text editor rather than the terminal?

grep -nr “blog” –exclude={global.min.js,*.html} projFolder/ > searchResults.txt

With that command, a new file called searchResults.txt will be created in the directory from which the grep command was executed.

A tool like grep is very useful and it help save a lot time when familiarising yourself with a new project. To know more about grep, simply open the terminal and type

man grep

Like the blog? Subscribe for updates

If you find any of my posts useful and want to support me, you can buy me a coffee 🙂

Or you can  buying or even try one of my apps on the App Store.

Also, if you can leave a review on the App Store or Google Play Store, that would help too.


Leave a Reply

Avatar placeholder

Your email address will not be published.