To Love One’s Craft: Fun with grep and RegEx…

I just read an interesting post by Dave Nelson (spugbrap) in which he details all the fun he had writing a script to search through Ext JS source code and open it with Textpad.

So, I checked the TextPad help to see if I could pass in the name of a file containing full file paths for TextPad to open.

You just need to put an at sign (@) before the filename, and TextPad will look at that file to find a list of files to open. So, I decided to create a temporary file, output the filenames found and converted by my set of commands (above) into that temporary file, and then run TextPad, passing the temporary filename preceded by an @ sign.

textpad $(for g in 'for f in \'grep -Rli "new Ext.Panel" *\'; do (grep -Hn -m 1 "new Ext.Panel" $f | sed -e 's/\(^[^:]\+\):\([0-9]\+\):.*$/\1(\2/g'); done'; do echo 'cygpath -w -a ${g/\(*/}'\(${g/*\(/},'grep -m 1 "new Ext.Panel" ${g/(*/} | sed -e 's/\t/ /g' -e 's/new Ext.Panel.*$//g' | wc -c'\); done) &

I’m sure this could be done more efficiently, but this was a fun challenge to take on, and I managed to find a way to do what I wanted to do.

Read on…

Claude is as a solutions architect at a unified communications company. He also helps small businesses increase their productivity, improve back-office processes and reduce costs by promoting the use of new technologies.
This entry was posted in How-To and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>