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 [email protected]
_________________________________________________________________ Get a preview of Live Earth, the hottest event this summer - only on MSN http://liveearth.msn.com?source=msntaglineliveearthhm
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 [email protected]
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 [email protected] 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 [email protected]
From: [email protected] To: [email protected] Subject: Re: Need script help. Date: Thu, 21 Jun 2007 09:05:37 -0500 (CDT) MIME-Version: 1.0 Received: from kclug.org ([139.146.133.42]) by bay0-mc2-f19.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2444); Thu, 21 Jun 2007 07:05:45 -0700 Received: from localhost (localhost.localdomain [127.0.0.1])by kclug.org (Postfix) with ESMTP id 52334704E94;Thu, 21 Jun 2007 09:05:43 -0500 (CDT) Received: from kclug.org ([127.0.0.1])by localhost (kclug.org [127.0.0.1]) (amavisd-new, port 10024)with ESMTP id A1aRDoqNnn3x; Thu, 21 Jun 2007 09:05:42 -0500 (CDT) Received: from kclug.org (localhost.localdomain [127.0.0.1])by kclug.org (Postfix) with ESMTP id 610CC704E90;Thu, 21 Jun 2007 09:05:41 -0500 (CDT) Received: from localhost (localhost.localdomain [127.0.0.1])by kclug.org (Postfix) with ESMTP id 108E5704E8Ffor [email protected]; Thu, 21 Jun 2007 09:05:40 -0500 (CDT) Received: from kclug.org ([127.0.0.1])by localhost (kclug.org [127.0.0.1]) (amavisd-new, port 10024)with ESMTP id 1-JS7g4XOZBL for [email protected];Thu, 21 Jun 2007 09:05:39 -0500 (CDT) Received: from mail.bradandkim.net (110.47.124.24.cm.sunflower.com[24.124.47.110]) by kclug.org (Postfix) with ESMTP id C936B704E8Cfor [email protected]; Thu, 21 Jun 2007 09:05:39 -0500 (CDT) Received: from localhost (localhost.localdomain [127.0.0.1])by mail.bradandkim.net (Postfix) with ESMTP id 4320EE0159Afor [email protected]; Thu, 21 Jun 2007 09:05:39 -0500 (CDT) Received: from mail.bradandkim.net ([127.0.0.1])by localhost (mail.bradandkim.net [127.0.0.1]) (amavisd-new, port 10024)with ESMTP id 09804-09 for [email protected];Thu, 21 Jun 2007 09:05:37 -0500 (CDT) Received: from webmail.bradandkim.net (localhost.localdomain [127.0.0.1])by mail.bradandkim.net (Postfix) with ESMTP id C5B25E01593for [email protected]; Thu, 21 Jun 2007 09:05:37 -0500 (CDT) Received: from 129.237.174.144(SquirrelMail authenticated user [email protected])by webmail.bradandkim.net with HTTP;Thu, 21 Jun 2007 09:05:37 -0500 (CDT) X-Message-Info: txF49lGdW40IdOmWLQfKf4GrcYHusV9u5v5rQzZwOdtJgs5qAHICYz3nwSl9+Rfe X-Original-To: [email protected] Delivered-To: [email protected] References: [email protected] User-Agent: SquirrelMail/1.4.10a-1.fc6 X-Virus-Scanned: Maia Mailguard 1.0.1 X-BeenThere: [email protected] X-Mailman-Version: 2.1.9 Precedence: list List-Id: KCLUG mailing list <kclug.kclug.org> List-Unsubscribe: http://kclug.org/mailman/listinfo/kclug,mailto:[email protected]?subject=unsubscribe List-Archive: http://kclug.org/pipermail/kclug List-Post: mailto:[email protected] List-Help: mailto:[email protected]?subject=help List-Subscribe: http://kclug.org/mailman/listinfo/kclug,mailto:[email protected]?subject=subscribe Errors-To: [email protected] Return-Path: [email protected] X-OriginalArrivalTime: 21 Jun 2007 14:05:46.0130 (UTC) FILETIME=[43602F20:01C7B40D]
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 [email protected]
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 [email protected] http://www.bradandkim.net
Kclug mailing list [email protected] http://kclug.org/mailman/listinfo/kclug
_________________________________________________________________ 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 [email protected] wrote:
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 ...
{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...
The file contains around 1400 records or more. Each record needs to be processed as above.
Does this make sense? Any ideas?
Thanks, Monty! I will pass it along.
Jeffrey A. McCright, A+ 816-210-3107 [email protected]
From: "Monty J. Harder" [email protected] To: "Jeffrey McCright" [email protected] CC: [email protected] Subject: Re: Need script help. Date: Thu, 21 Jun 2007 11:24:55 -0500
On 6/21/07, Jeffrey McCright [email protected] wrote:
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 ...
{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...
The file contains around 1400 records or more. Each record needs to be processed as above.
Does this make sense? Any ideas?
_________________________________________________________________ Hotmail to go? Get your Hotmail, news, sports and much more! http://mobile.msn.com
On 6/21/07, Jeffrey McCright [email protected] wrote:
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 ...
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 [email protected]
From: djgoku [email protected] To: [email protected] Subject: Re: Need script help. Date: Thu, 21 Jun 2007 11:39:13 -0500
On 6/21/07, Jeffrey McCright [email protected] wrote:
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 ...
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 _______________________________________________ Kclug mailing list [email protected] http://kclug.org/mailman/listinfo/kclug
_________________________________________________________________ Hotmail to go? Get your Hotmail, news, sports and much more! http://mobile.msn.com
On 6/21/07, Jeffrey McCright [email protected] 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 [email protected] wrote:
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 [email protected]
If your friend can give a sample dataset, I can whip up a Python script ASAP.