RE: BASH + Best method of converting fields to variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The problem with your solution is that, before you've done any actual work, you've already read the file twice. I'm not sure how many users you're trying to batch, but this will get tedious, probably starting at 100 or so.

You should make a practice of attempting to read a file one time, and doing the processing you need on each line. To do otherwise is extremely inefficient.

----
Robert P. Nix                            internet: nix.robert@xxxxxxxx
Mayo Clinic                                  phone: 507-284-0844
RO-CE-8-857                                page: 507-270-1182
200 First St. SW 
Rochester, MN 55905      
----   "Codito, Ergo Sum" 
"In theory, theory and practice are the same,
 but in practice, theory and practice are different."



> -----Original Message-----
> From:	fedora-list-bounces@xxxxxxxxxx [SMTP:fedora-list-bounces@xxxxxxxxxx] On Behalf Of Ow Mun Heng
> Sent:	Saturday, July 17, 2004 2:56 PM
> To:	For users of Fedora Core releases
> Subject:	Re: BASH + Best method of converting fields to variables
> 
> I figure that since I am supposed to have like 6 fields per line, I can do this
> 
> NoRecords=`cat $1 | wc -l`
> TotalNoFields=`awk -F':' '{ total = total + NF }; END {print total}' $1`
> let FieldsPerLine=$TotalNoFields/$NoRecords
> if [ $FieldsPerLine -ne "6" ]; then
> 	echo "Incorrect Number of Fields"
> 	usage
> 	exit 1
> fi
> 
> Cool.. That's one thing solved.
> 
> -- 
> Ow Mun Heng
> Fedora GNU/Linux Core 2 on D600 1.4Ghz CPU kernel
> 2.6.7-2.jul1-interactive 
> Neuromancer 12:34:55 up 14:36, 6 users, load average: 1.06, 0.89, 0.82 
> 
> 



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux