Tuesday, February 19, 2013

user friendly search on windows

Windows with its cmd.exe seems not to be user friendly environment for developer. But this may be changed easily, you need only to install few programs we miss from normal systems. See http://gnuwin32.sourceforge.net and download coreutils, findutils, sed, awk, grep etc. and put them to PATH. As find.exe confilicts with windows file.exe I always rename it to gfind.exe . You have to be careful with quoting - only double quote is welcomed. Also paths may be tricki, remember to replace / with \. Eg. xargs needs extra backslash to interpret one properly.

Let's find all inserts in sql files.

find . -name '*.sql' | xargs grep insert 
It is the win32 version:
gfind . -name "*.sql" | sed s!/!\\\\!g | xargs grep insert

Summary: having in mind few simple rules you may make your system much easier to talk to.