2007-12-31 19:37I love the console (and Python?)While I stand by everything I’ve said about the problems with the console environment, I have tried to be open-minded enough to acknowledge its benefits. That’s not particularly hard, as I often make use of some tool that is (currently) only available on the command line or get a job done faster because it is well suited to a text- / keyboard-based system. Using the console is also getting easier and more productive, though, thanks in part to Python, strangely enough, but that’s a matter for another post. This post is about what can be achieved using just a standard console and utilities. Solving problems with the consoleFirstly, as an example of where familiarity with standard console utilities was useful, there is the task I was set a few weeks ago by my boss. He was trying to configure lircd, which uses text config files containing (in some places) hex strings that represent pairs of bytes. Unfortunately for him, he had got the byte order wrong, such that in trying to express, for example, the bytes “1A” and “2B” he had written “0x1A2B” instead of “0x2B1A” (or perhaps the other way around). He had emailed me such a config file, and when I loaded it up in Kate I found that the strings that needed changing were nicely arranged in blocks. My instinctive reaction was to enable block selection mode and select a long column of the first two characters, then cut it and paste it after the second column (which, after the cut, had become the only column). This was a valid solution to a problem, so I emailed back the resulting file, along with the method used to create it, and was informed that, although the file was now in the correct form, I had misunderstood the scale of the problem. My boss had actually created several, perhaps millions, of these files, and needed an automated way of making this change to them all, a fact I hadn’t appreciated, at least partly because of the body of his original email which said simply “Here’s the file.” Undaunted, I continued, changing mindset and jumping into the console. I remembered a time when I was trying to write an OCR program as a BASH one-liner (it’s a long story, and an even longer one-liner) and had tried catching and replacing patterns using sed. Catching and changing the order of patterns seemed even easier, so I started writing:
or at least that’s what I got after perhaps fixing a few syntax errors. Pleased with myself, I sent this little one-liner back in an email, and my boss a bit later called across the office to thank me, and to “bestow” upon me “the unnecessary use of What’s Python appreciation month? Can you not wait 5 minutes for me to publish my next post? Trackbacks
Trackback specific URI for this entry
No Trackbacks
|
QuicksearchCategoriesSyndicate This BlogBlog Administration |