The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help... no idea what to use dakid Shell Programming and Scripting 4 03-06-2008 12:57 AM
using case to do this might be a bad idea? Skyybugg Shell Programming and Scripting 12 04-06-2007 02:19 PM
any good idea on this? fedora Shell Programming and Scripting 7 09-29-2006 03:36 PM
an idea? /var/adm/message pressy UNIX for Advanced & Expert Users 3 08-19-2003 07:04 AM
Dual Boot a good idea? PravusMentis UNIX for Dummies Questions & Answers 8 07-18-2001 03:02 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-08-2005
yongho yongho is offline
Registered User
  
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Limitations of awk? Good idea? Bad idea?

Keeping in mind that I'm relatively comfortable with programming in general but very new to unix and korn/bourne shell scripts..

I'm using awk on a CSV file, and then performing calculations and operations on specific fields within specific records. The CSV file I'm working with has about 600 records, with 30 fields.

Since I want to be able to cross-reference one record against all other records multiple times for different/specific records that need to be checked (for example if a record orders an amendment to a previous record, I'd like to check to see if the previous record still exists), and since, I think, awk only runs through each record once, I wanted to know if it's possible, and if so, if it's even a good idea to store all the fields from each record that I need (I don't need all of them, just maybe a third of the information) into an array in awk, and then return the array itself, outside of awk.

Possible? Good idea, bad idea? I'm open to all suggestions and advice.
Note: I don't know if it's possible to run the loop for each record again once you're in the awk program, for example: a nested awk where in the middle of the loop for the host awk, you can start a second awk to check the current record in the original awk against all other records.
  #2 (permalink)  
Old 06-08-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
It's somewhat difficult to follow the thread, but.... I think I understand what you're after.

Usually you don't to store ALL the records, but rather one record per key - where the 'key' is your 'unique identifier' for the type of a record.

Awk has a notion of the 'associative arrays' - very similar to perl's hashes. You can store by a 'key', update by a 'key' and lookup by a 'key'.

You can process your CSV once, store the relative pieces of a file in the array, manipulate the array cells as you go AND post-process the content of the array in the awk's 'END' session [by iterating through the array: for( i in array)].

The associative arrays are dynamic in nature and their size is bound only by the available memory. Seems like you don't have huge files to process - you should be ok.
  #3 (permalink)  
Old 06-08-2005
yongho yongho is offline
Registered User
  
 

Join Date: Jun 2005
Location: New York City
Posts: 95
Thumbs up Thanks again.

Sorry about the lengthy thread, I usually try to make my inquiries with as much detail as possible to avoid confusion but half the time I guess I achieve the opposite.

Yes, you understood my thread perfectly. And yes, I think that will be enough for what I wish to do now.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0