My New Year’s Resolution
In 2011 my New Year’s resolution is to do more things the easy way, even if it takes longer the first time. I am going to stop using brute force to solve problems. In particular:
- I am finally going to memorize how one redirects both stderr and stdout to the same stream. (
2>&1 |
) - I am going to learn the sed? trick my advisor showed me 20 years ago for repeating a command from the shell history while substituting one word for another, instead of just using the arrow key to backup to and erase the string. (
^string1^string2^
or!!:s/string1/string2/
or for global substitution, not just the first occurrence!!:gs/string1/string2/
) - I am going to increase my regex fu and use regular expressions consistently instead of just editing 20 lines of copy and paste code. (This would be easier if every editor didn’t have subtly different syntax.)
- I am going to use Python to automate repetitive tasks.
January 1st, 2011 at 10:17 am
Rather than sed, I advise learning ack. Unlike sed, it actually has a functional (and consistent) regular expressions flavor. Specifically, it’s just using Perl’s regexp engine, which makes it (a) brutally fast, and (b) much easier to learn and use.
January 1st, 2011 at 2:54 pm
Daniel, do you mean awk? If so, awk does not use Perl’s regex engine. In any case, sed has Posix basic regexen, whereas awk has Posix extended regexen. Awk can do a lot more than sed, but much less than Perl, which is why it has mostly withered in recent years. I still occasionally use it from the command line, though.
January 2nd, 2011 at 1:28 am
He may mean ack, at http://betterthangrep.com. But, like grep, it only searches content, so it’s not a replacement for sed.
January 6th, 2011 at 10:35 am
I’ve found that a handy alternative to sed is Super Sed (ssed). It provides a more extended regex syntax with some similarities to Perl’s expressions.
January 22nd, 2012 at 2:48 am
Man, I’m still struggling with basic php ๐