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

Bruce Smith members@kalamazoolinux.org
08 Jul 2002 13:31:12 -0400


> 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.
> 
> 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.
> 
> Ideally, I will be able to cron this thing and come to work
>  in the morning after the magic has happened.

It IS possible to process files one line at a time in a shell script,
but it's not very efficient.  If the file is large, I'd look elsewhere,
but if it's a small file it can work fine.

If the file is small and you want to pursue this, please post more
details on what you want to do.  Plus a sample input file, and what the
output file(s) should look like.  I'll whip you up an example script. 
It's easier to show in an example, than try to explain.

--------------------------------------------
Bruce Smith                bruce@armintl.com
System Administrator / Network Administrator
Armstrong International, Inc.
Three Rivers, Michigan  49093  USA
http://www.armstrong-intl.com/
--------------------------------------------