How many times have you used your code editor to look for some text and either didn't find what you were after, or worse yet - were told that it's not there when in fact it was? I bet this has happened to us all at some stage, and after some struggle you master the editor and life goes on, however I want to go over some basic tools/commands that you can always fall back to.
One of the most useful is searching through files. In the windows world you should all know about findstr. In particular the following variation:
findstr /snip /c:"string to look for" *.cpp
This command will go through all sub directories, ignoring case, looking through all cpp files for the specified string. And it never lies. In the linux world you want to use something like this:
find . | xargs grep 'string to look for'
If you find yourself repeating steps like this often, place the command in a script. Here is the one I use (it ignores SVN hidden folders and uses color output):
#!/bin/bash
find . ! -path "*.svn*" | xargs grep "$1" --color=always
I generally build up a range of scripts for everything I repeat to make life easier. What about you? What are your top few software shortcuts?
- Login to post comments
-


Duncan Bayne | Fri, 2009-04-17 02:06
My favourite software shortcut is Emacs ;-)
Seriously, Emacs is fantastic. Take search and replace for example. Simple editors allow simple search and replace, whereas more advanced editors allow the use of regular expressions and / or wildcards.
Emacs, on the other hand, allows you to search for a regular expression pattern, pass the text you've found into an arbitrary Emacs Lisp expression, and then replace the text with the return value from the expression. Details here.
Basically I'm taking the approach that if there's something I'd normally write a script to do, then I can probably do it in Emacs out of the box, and if not there's probably a plugin for it, and if not then I can just write some ELisp to do it.
- Login to post comments
»Armin | Thu, 2009-04-09 16:55
You can perform all the above searching by using only grep as well:
grep 'string to look for' * --exclude-dir=".svn" -R --color=always
Your favorite code editor should have similar tools; e.g. Emacs has 'find-grep-dired'.
- Login to post comments
»