In the Margin: Where are these Ubuntu lovers?
30 Oct 2008
On the US frontpage to the Ubuntu shop, there are 6 friendly people wearing copies of the same shirt that says, “I do it with ubuntu.” Where are these people? I’d like to hang out with them.
Observation: I Value Underwhelming, Useful Tools
29 Oct 2008
As I reflected on my engineering values this evening over a good cup of coffee, I noticed a common theme: I value underwhelming, useful tools.
Many of the underwhelming, useful tools I value (including tools which have been around for decades along with those which are only ideas in my head) fall into two distinct categories:
- web applications
- command-line tools
By underwhelming, I mean distinctly not overwhelming, not even remotely so, though Merriam-Webster defines underwhelming as “failing to impress or stimulate.” Perhaps both are accurate to my point. If a software tool is simple and all too useful, it no longer feels like software, it fails to continue to impress, and is able to become one with your activity space.
Not all underwhelming tools are useful, which is why I value tools both underwhelming and useful. When a tool is overwhelming, it may be difficult to understand its utility. When a tool is underwhelming, its utility quickly presents itself.
I find this blog underwhelming at times…
Now to make it useful…
Easy Lab: Map Caps Lock to Control in X Windows
22 Oct 2008
Motivation
I use the control key a lot. Between my Fluxbox keys file shortcuts, several Xterms with bash, and Emacs, the pinky on my left hand is getting worn out quickly. It may not seem productive at first, but every engineer should spend some time setting up the simple things in his or her lab, including getting a comfortable keyboard.
Using
- a standard US keyboard
- a UNIX-like system running an X windows server (if you are on a UNIX-like system and have a graphical display, you are probably running X windows)
- xmodmap
Setup
Here is my $HOME/.Xmodmap file:
! map Caps Lock key to Control remove Lock = Caps_Lock keysym Caps_Lock = Control_L add Control = Control_L ! map right Windows/Super key to Caps Lock remove Mod4 = Super_R keysym Super_R = Caps_Lock add Lock = Caps_Lock
To activate it, wait until you restart X or run from the command line:
$ xmodmap $HOME/.Xmodmap
Done. Now I just need to break the Control_L habit. Fortunately, I kept that key mapped as Control_L so it still works as expected. This feels like the old days in the UNIX workstation lab, except that my keyboard is much, much cleaner.
Using
- a UNIX-like system
- some implementation of sed, I’m using GNU sed
- a shell, I’m using GNU bash
- text files
Introduction & Motivation
As a command-line user on many Unix-like systems, I often run into a simple problem: how do I (simply) selectively grab one line out of a text file — especially when I know it’s line number?
It sounds stupidly simple, but it may not be stupidly obvious even if you’ve used UNIX and UNIX-like systems for a while. An obvious approach is to head a text file and pipe it into tail, like so:
$ # print line 2 in myfile.txt $ head -2 myfile.txt | tail -1 $ # format: head -N myfile.txt | tail -1 $ # where N is line number
This is not exactly efficient, especially if the line number (N) is quite large, as head will print all lines up to N into stdout for tail to grab the last one. However, this is a natural and very easy task for sed.
Setup
Find a file you like, or create a text file with 10 or more lines, listing the line number on each line. Here is my text file:
$ cat sedme.txt one two three four five six seven eight nine ten
Exercise 1: Print Just One Line
$ sed -ne 2p sedme.txt two
Exercise 2: Print Several Lines
$ sed -ne 2,4p sedme.txt two three four $ sed -ne 2,10p sedme.txt two three four five six seven eight nine ten $ sed -ne 2,11p sedme.txt two three four five six seven eight nine ten
Note that it’s okay we asked for line 11 even though it doesn’t exist. It just printed up to the end of the file.
Exercise 3: Print Lines Based on a Pattern
$ sed -ne /two/,/four/p sedme.txt two three four
I imagine that some systems may require you to wrap the sed expression in quotes, like so.
$ sed -ne "/two/,/four/p" sedme.txt or $ sed -ne '/two/,/four/p' sedme.txt
Tell Me More
See sed’s info or man page for documentation. We used the following options (descriptions from “info sed” of GNU sed 4.1.2):
`-n'
`--quiet'
`--silent'
By default, `sed' prints out the pattern space at the end
of each cycle through the script. These options disable
this automatic printing, and `sed' only produces output
when explicitly told to via the `p' command.
`-e SCRIPT'
`--expression=SCRIPT'
Add the commands in SCRIPT to the set of commands to
be run while processing the input.
…and the following command:
`p'
Print out the pattern space (to the standard output). This
command is usually only used in conjunction with the `-n'
command-line option.
We will also used addressing by regular expression for exercise 3:
/regexp/
Match lines matching the regular expression regexp.
Isn’t it amazing how much you can write about something so simple and elegant?

