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.

5 Responses to “My New Year’s Resolution”

  1. Daniel Spiewak Says:

    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.

  2. John Cowan Says:

    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.

  3. Andy Lester Says:

    He may mean ack, at http://betterthangrep.com. But, like grep, it only searches content, so it’s not a replacement for sed.

  4. Paul Hatton Says:

    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.

  5. Navnebetydning Says:

    Man, I’m still struggling with basic php ๐Ÿ˜‰