Limitations of awk? Good idea? Bad idea?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Limitations of awk? Good idea? Bad idea?
# 1  
Old 06-08-2005
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  
Old 06-08-2005
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  
Old 06-08-2005
MySQL 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.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compact script with array - Good idea?

Hi, I have a shell script where a lot of the code is repeated. I wanted to make the code much more compact so I spoke to a guy and he suggested using arrays, like follows: #!/bin/bash readonly -a nginx=('nginx' '--prefix=/opt' '-j 4' 'http://nginx.org/download/nginx-1.2.2.tar.gz' )... (2 Replies)
Discussion started by: Spadez
2 Replies

2. Red Hat

Is overlapping two RAID5 arrays on same drives a bad idea ??

is placing two RAID5 arrays on disk as shown below Is advisable? Will this create performance problems? sda-(500GB) sdb-(1TB) sdc-(1TB) sdd-(1TB) (250MB)----------(250MB) ---------unused------------unused------->(/dev/md0) RAID1 ... (6 Replies)
Discussion started by: Saed
6 Replies

3. UNIX for Advanced & Expert Users

echo 1 > /proc/sys/vm/drop_caches a good idea?

Hi folks. I work with several production servers, and I have seen in some Kernel Cache using most of the memory. See this pic: http://i51.tinypic.com/301nb6c.jpg Do you think this is a smart choice? Remember these are productions servers and it is extremely necesary this does not... (6 Replies)
Discussion started by: erick_tuk
6 Replies

4. OS X (Apple)

Deleting a recursive symbolic link was a very bad idea

Well i was tidying up some files in a very important directory on our development server and somehow some plank had put a recursive sybmolic link in it. Which I the even bigger plank tried to delete from my FTP client. My FTP client then thought it would be OK to delete not only the sybmolic link... (0 Replies)
Discussion started by: timgolding
0 Replies

5. Shell Programming and Scripting

using case to do this might be a bad idea?

Reading this file. I want to read all 4 fields. If 2 is populated with a p, I want to set $TYPEP to "Printers", if not should be empty. If 3 is populated with an r, I want to set $TYPER to "REQ Printers" if not should be empty. If 4 is populated with letter o, I want to set $TYPEO to... (12 Replies)
Discussion started by: Skyybugg
12 Replies

6. Shell Programming and Scripting

any good idea on this?

txt file like this, 1 2 3 4456 a bb c d 3 f e 1 k 32 d m f e 123 m 2 k every line contains 3 or more columns, all the columns are separated by space, and every column includes 1 to 3 character. what I wanna do is deleting the first three columns, and keep the rest no matter how long... (7 Replies)
Discussion started by: fedora
7 Replies

7. UNIX for Dummies Questions & Answers

Why is it Bad Idea to insert "." (Dot) to PATH ?

I was told that it's a Bad Idea (especially for root ) to Add To the Variable $PATH in unix the ":." (dot), In order to execute programs in my current directory without typing ./program For example: PATH=$PATH:$HOME/bin:. Does someone know why is it a Bad Idea? (2 Replies)
Discussion started by: amitbern
2 Replies

8. UNIX for Dummies Questions & Answers

Dual Boot a good idea?

I was just wondering if it would be alright to dual boot a machine with both UNIX using XTERM for the interface and windows 98 or if people consider this a bad idea? if you consider it bad do tell me some possible alternatives..also would it be better to get linux over pure unix? I'd like a visual... (8 Replies)
Discussion started by: PravusMentis
8 Replies
Login or Register to Ask a Question