Need script help.

brad at bradandkim.net brad at bradandkim.net
Thu Jun 21 09:05:37 CDT 2007


> All,
>
> I have a friend who needs to run a shell script to process data in a space
> or comma delimited file. I think SED or AWK may be needed here, but I
> don't
> program so I need help. The ASCII File structure is similar to the
> following:
>
> Lastname Firstname internalphonenumber externalphonenumber phoneextention
> MACaddress ...
> Lastname Firstname internalphonenumber externalphonenumber phoneextention
> MACaddress ...
> Lastname Firstname internalphonenumber externalphonenumber phoneextention
> MACaddress ...
> Lastname Firstname internalphonenumber externalphonenumber phoneextention
> MACaddress ...
>
> The fields are variable length.
>
> My friend needs to be able to plug in commands in this script file so that
> she can have something like:
>
>
> {command} Lastname {command} Firstname {command} internalphonenumber
> {command} externalphonenumber ...
>
> etc...
>
> The file contains around 1400 records or more. Each record needs to be
> processed as above.
>
> Does this make sense? Any ideas?
>
>
> Thanks,
>
> Jeffrey A. McCright, A+
> 816-210-3107
> jmccright at hotmail.com
>

I think awk would be best for this.  Something like

cat <file> |awk '{ print "<command>" " " $1 " " <command> " " $2}' >
<newfile>

When you cat the file and pipe it into awk, awk will look at it line by
line and set $1 as the first field, $2 as the second field and so forth. 
By default awk uses spaces and/or tabs as the field delimiter but that can
be changed.   In the above command, the " " is just to print a space
between your command and the argument.  Hope that helps.



Brad Crotchett
brad at bradandkim.net
http://www.bradandkim.net



More information about the Kclug mailing list