Stand back, I know regular expressions
Thursday, January 3rd, 2008So, after the last blog post, I was talking to Seveas and mentioned how I thought with all the nifty and useful commands coming in on here, I might make a niftyutils package. The conversation is as follows
<Mez> thinking of compiling a few of these into a nifty-utils package
<Seveas> so we have coreutils, moreutils and nifty-utils?
<Seveas> just contribute them to moreutils
<Mez> and a few more
<Mez> patch-utils being the most obvious
<Mez> findutils, psutils …
<Seveas> dennis@mirage:~$ apt-cache -n search utils | wc -l
<Seveas> 266
Ok, so I had to get one up on this, as I only wanted fooutils, not foo-utils or foo-utils-bar, and came up with
apt-cache search utils | awk '{print $1}' | egrep '^.*[^-]utils$' | wc -l
for which I got told off. Awk can do everything, so why pipe to grep?
After a bit of back and forthing, the equivalent command, without egrep is
apt-cache search utils | awk '/^[[:alnum:]]*([-[:alnum:]])*[^-]utils[[:space:]].*/' | wc -l
I think the first version was prettier.
Oh, and another comment relating to my last post, specially going out for “Bork Fomb”:- I’ve deleted your post, and I’m glad I have approval on here - you could have done some damage to people who didn’t know what that does, so here’s a special command, just for you
sudo iptables -I INPUT -s 77.185.71.113 -j DROP