purejunk

Added this line to prove it changed.

Like all of my examples this one is "really dumb": in other words, it tries to show exactly what it needs to, no more and no less. It can be used as a building block for something much more complicated.

This particular example could be thought of as "building a database", which you could use to save and retrieve information you need for administration.

It comes from this particular problem. Lingtao sent me an email which contains the name and address of each of the machines we will use. I would like to have these in the form of a "character-separated database". I am choosing the "pipe symbol" '|' as the separator (it does not conflict with commas and semicolons and dots and stuff).

On the other hand "keeping it in quotes" so the shell does not interpret it as a pipe command will raise h*ll with your life:-.

So I need a "little program" to read in the txt file I made from Lingtao's email, which has the name, some space, the address, and create a text file which has address|name as its entries. Then I need a couple of little tiny functions that will produce name from address or address from name.

I know I could do it all "in Perl" or in 1000 other languages/ways, and for such a small collection of data it is sort of silly to automate it. Most "old-line" actual Unix admins are comfortable with just "throwing a script together", so this is about the simplest usable example of such a thing I could make.

One very frustrating thing about shell scripts is that the syntax is a bit strange at times, and the parser is VERY unforgiving. I tend to write mine in "baby steps" as a result, and test the pieces before writing the whole.

zipped source code

Code links

usa-addresses.dtb
usa-addresses.txt
getname

Listings

usa-addresses.dtb
cu301a|134.48.13.150
cu301b|134.48.13.149
cu301c|134.48.13.148
cu301d|134.48.13.147
cu301e|134.48.13.146
cu301f|134.48.13.145
cu301g|134.48.13.144
cu301h|134.48.13.143
cu301j|134.48.13.142
cu301k|134.48.13.141
cu301m|134.48.13.140
cu301n|134.48.13.153
cu301p|134.48.13.152
cu301q|134.48.13.151
cu301r|134.48.13.160
cu301t|134.48.13.162
hp.laserjet.2200|134.48.13.139

usa-addresses.txt
cu301a   134.48.13.150
cu301b   134.48.13.149 
cu301c   134.48.13.148 
cu301d	 134.48.13.147 
cu301e   134.48.13.146
cu301f   134.48.13.145
cu301g   134.48.13.144
cu301h   134.48.13.143 
cu301j   134.48.13.142 
cu301k   134.48.13.141 
cu301m   134.48.13.140 
cu301n   134.48.13.153
cu301p   134.48.13.152
cu301q   134.48.13.151
cu301r   134.48.13.160
cu301t   134.48.13.162
hp.laserjet.2200 134.48.13.139

getname
IFS="|"
while read a b
do 
  if [ $b == $1 ]
  then echo $a
  fi
done