Saturday, May 31, 2008

Grepping and Awking text

I have been working today on retrieving, formatting, and displaying text in a certain way and have learned a lot about grep and awk. For instance, grepping strings with hyphens isn't as easy as "grep -dev". What you need to do is "grep [\-\]dev". I was also needing to get every other line of output from one command, and I found a way to do that in awk:

command | awk 'NR > 2 && (NR % 2 == 0 ){ print} /^$/{NR=0}' | xargs other_command

This stuff is quite fun. Hopefully, pretty soon, I will have a bunch of scripts that get what hardware you have (as seen by linux) and get the Windows-driver counterpart among other things.

No comments:

Post a Comment