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@hotmail.com
_________________________________________________________________ Get a preview of Live Earth, the hottest event this summer - only on MSN http://liveearth.msn.com?source=msntaglineliveearthhm
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@bradandkim.net http://www.bradandkim.net
Hmmm... I think it might. Thanks for your help. I will -pass it on and have her try it.
Thanks for the help! Have a great day!
Thanks,
Jeffrey A. McCright, A+ 816-210-3107 jmccright@hotmail.com
_________________________________________________________________ Get a preview of Live Earth, the hottest event this summer - only on MSN http://liveearth.msn.com?source=msntaglineliveearthhm
On 6/21/07, Jeffrey McCright jmccright@hotmail.com wrote:
{command} Lastname {command} Firstname {command} internalphonenumber
{command} externalphonenumber ...
It's not clear whether you want to produce a new file interpolating some command(s) with these values or what, exactly
cat asciifile | while read LName FName IntPhn ExtPhn PhExt MAC Junk do echo "{command} $LName {command} $FName {command} $IntPhn {command} $ExtPhn {command} $PhExt {command} $MAC" done >outputfile
You may find the read metaphor easier than awk for this, because it's such a PITA to get the extra quoted spaces in there. You especially may find this works better if instead of just producing this output, you're actually needing to run some command(s) inside the while loop.
Note the Junk at the end of the read statement. It slurps up any extra words on the input line past the last variable name. That way the MACvariable doesn't get junk in it.
etc...
Thanks, Monty! I will pass it along.
Jeffrey A. McCright, A+ 816-210-3107 jmccright@hotmail.com
_________________________________________________________________ Hotmail to go? Get your Hotmail, news, sports and much more! http://mobile.msn.com
On 6/21/07, Jeffrey McCright jmccright@hotmail.com wrote:
test is the file with this data: Lastname Firstname internalphonenumber externalphonenumber phoneextention MACaddress
Also replace command with the command of your choice.
# space delimited $ perl -n -e 'chomp; (@data) = split / /; system "command", @data;' test
# comma delimited $ perl -n -e 'chomp; (@data) = split /,/; system "command", @data;' test
Thanks, I will pass this along.
Jeffrey A. McCright, A+ 816-210-3107 jmccright@hotmail.com
_________________________________________________________________ Hotmail to go? Get your Hotmail, news, sports and much more! http://mobile.msn.com
On 6/21/07, Jeffrey McCright jmccright@hotmail.com wrote:
Thanks, I will pass this along.
If you need any clarification of what that whole thing is doing I will be glad to give it.
On 6/21/07, Jeffrey McCright jmccright@hotmail.com wrote:
If your friend can give a sample dataset, I can whip up a Python script ASAP.