[KLUG Members] To shell or not to shell...

Adam Williams members@kalamazoolinux.org
08 Jul 2002 12:58:47 -0400


>I hold firm the belief that every network guy is a
>frustrated programmer and vice versa. Same holds true for
>guitar players and drummers. Please bear with me, as I am
>more of a network guy. :)
>I need to take an export file, and process it to two
>different output files. The file is currently in a fixed
>width, one record per line format. It needs to go to an
>LDIF file and a DOS batch file, both of which are plain
>text.

There are lots of LDIF manipulators/creators floating about, are sure
one of them won't help you?  There are utilities for processing csv
files into LDIF,  which is almost what you want.

>I'm trying to figure out how I can process this export file
>one line at a time in a shell script, but I'm starting to
>think I can't. I'm thinking I need to write a little C
>program to read each line into an array, walk through it
>as necessary, and write out to the text files. I'd rather
>do it with bash, but am failing to find how. Everything I
>read about I/O with shell scripts is just redirection.
>Nothing on how to open a file for reading line by line.

'Real' I/O processing with shell scripts is hard as there isn't any low
level open and read functions.

The first thing I would try is awk.  Failing that I'd use something like
php or perl. (Personally I'd use php as perl is way too much of a PITA
to get up and running).