Justace’s Blog

Thoughts and Experiences

Archive for the ‘Uncategorized’ Category

Regular Expressions

Posted by Justace Clutter on November 13, 2008

From time to time I just really fall in love with Unix (well, Linux for you purists)…  In windows it can be very difficult to get a quantity.  A click here, a click there, install update, reboot…  Then well at least 5 more clicks.  Well, Unix to the rescue.  The power comes from the ability to combine several different small programs in ways that the original programmer had not even thought of to get a result.  Case in point…

egrep ‘.*(nan|bweight.*[^.]).*’ analysis_trigger_nocuts.out | egrep -v ‘[.]‘ | uniq -c | awk ‘{ print $1; }’ | grep 2 | wc -l

Here I needed to know how many events in my analysis had returned two “nan”’s (one for each jet).  I will not go into detail about what the above line really does, I just dont have time for that right now, but sufice it to say the answer is 484.  Add that to the number of events that gave me a zero weight for my btagging and then you have 1794…  The total number of nan lines in my output.  So, everything adds up.  That is nice.  The point is this…  The power of unix comes not from huge programs that try to do everything, but from a combination of seemingly small programs that do small tasks well.  Seems like almost anything can be done with combinations if grep, egrep, awk, sed, wc, uniq, sort, and cut…

Posted in Uncategorized | Leave a Comment »