Unix Sig By Christopher J. Fearnley @SH = Next Month's Meeting Due to the PACS Computer Festival we will not have a formal meeting. Instead, we will meet informally after the Internet Presentation. @SH = Awk Scripts Awk is a very powerful language for massaging input from one format into another format (as well as numerous other things). It is even powerful enough to write an assembler (Henry Spencer of the University of Toronto has done this - though he should have used a more appropriate tool!). I was inspired by our speaker's (Steve Beuret) use of awk to write a short script to filter the standard input into columnar format. I then remembered that Kernighan and Pike had a command to do this in their book _The UNIX Programming Environment_. I looked it up and they wrote a shell script called "2". $ cat 2 # 2, 3, ... Print in n columns pr -$0 -t -l1 $* Then they created the following links to 2: ln 2 3; ln 2 4; ln 2 5; ln 2 6. So ls | 3 will print the output in 3 columns and ls | 5 will print in 5 columns. You may remember that pr is the command to convert text files for printing. The "-$0" means put the output in $0 columns (Note: The shell parses the command line into words and stores the words into the variables 0, 1, .... So all the command's arguments are available to shell scripts and programs by the construct $1, $2 and so on while the command name itself is stored in the variable 0. ) The "-t" means don't print the 5 line header and footer. "-l1" means set the page length to 1 line and finally $* is a shell idiom meaning all the command line arguments (i.e., $1, $2, ...). Of course I had to test this out on my Linux-box. It didn't work. For some reason bash (the GNU Bourne-Again SHell) interprets $0 as the full path length /usr/local/bin/2 which pr chokes on. So I had a perfect opportunity to modify the K&P script with awk (note also that I'm using the GNU version of awk and pr): $ cat 2 #! /bin/bash pr -`echo $0 | awk -F/ '{ print $NF }'` -l1 $* I'm using awk to filter out the junk at the beginning of the long path name bash gives for $0. So it only prints out the NF field (NF is the built in variable meaning the number of fields [fields are separated by "/" because of the "-F/" argument] in the current input record [which is provided to awk by "echo $0"]). Note also that I don't need the "-t" option because GNU pr omits headers and footers if the page length (the -l page-length option) is less than 10. @SH = Linux Notes This past week I've spent a lot of time trying to understand the development facilities under Linux. I learned that the kernel is 100% POSIX complient (the IEEE standard for a Portable Operating System interface). gcc, the GNU project C compiler, and the Linux standard C library are ANSI complient (well, that is if you use the -ansi -pedantic-errors options to gcc). Which means it should be relatively easy to port to and from the Linux environment. Unfortunately, I got lost in the maze of options gcc offers for optimizing compilation and linking. Looks like I've got some more RTFMing to do!