Regular Expressions

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…


About Justace Clutter

I am currently a Physics graduate student at the University of Kansas. My enphasis is High Energy Experiment and as such am currently working at the D0 experiment at Fermilab near Chicago. My undergraduate was accomplished at Southwest Missouri State University (now MSU) in Springfield, Mo. I also compleated 5 years of active duty in the Air Force just after high school.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s