Prefetch Technologies // Keeping your cache lines cozy

Archive

Posts in Shell

Massaging data with fmt and sed

shellSep 23, 2005 1 min read

I had to cleanup a few documents today, and wanted to transform the text into an 80-column file with 4 spaces in the left margin. This was easily accomplished with the following shell pipeline: I was lucky that the file had a basic form, since it minimized the number of items in my pipeline. :)

$ read more →

$() || `` ??

shellAug 15, 2005 1 min

While cleaning up some bash scripts tonight, I started to wonder which of the following two substitutions is clearer: or I really think the second form is a bit more clear, though it could throw off people who get ` and ' mixed up! Choices, choices!

$ read more →

Base conversions with bc

shellMay 4, 2005 1 min

Whiile reading through Planet Sun I stumbled across Chris Gerhard's base conversion post. I replied with an alternate solution using bc(1), which I have used extensively through the years. bc(1) is a command line calculator that can convert between bases when the "ibase" and "obase" options are used. The following example shows how to convert a base 10 number to it's hexidecimal equivalent: We can also use bc to convert a hexidecimal value to decimal: This gets even better…

$ read more →

Command line dictionary

shellJan 15, 2005 1 min

The UNIX tips mailing list provides daily UNIX hints and tricks: I received a tip a few months back that showed how to use lynx to lookup a word on dictionary.com, and decided to add this to my .profile: This function accepts an argument, and passes the URL with the word to lookup to lynx. The function can be invoked by typing "dict" at a shell prompt: The one who ruins my life with their clueless ways I had to throw that in :) Here is a real run: As you can see, this is rather useful (especially when you use vi to draft all of your documents).

$ read more →

Bash arrays

shellNov 14, 2004 1 min

I have been trying to get a better grasp of some advanced bash concepts, and have been reading through the following reference manual. I am pretty familiar with C and perl arrays, but have never had a need to use arrays in a bash script. The syntax for a bash array is almost identical to Perl: This assigns the value 12 to the first slot in the array. Since bash variables are untyped, we can assign a string to the same array: This assigns the string "my string" to slot two in the array…

$ read more →