Problem with lookup values on AWK associative array


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with lookup values on AWK associative array
# 1  
Old 11-13-2009
Problem with lookup values on AWK associative array

I'm at wits end with this issue and my troubleshooting leads me to believe it is a problem with the file formatting of the array referenced by my script:

Code:

awk -F, '{if (NR==FNR) {a[$1]=$4","$3","$2}\
else {print a[$1] "," $0}}' WBTSassignments1.txt RNCalarms.tmp

On the WBTSassignments1.txt file I have a few thousand lines each with 4 comma seperated fields:

Code:

WTBS-1001,SE01001T,North Creek,Brad Bradford
WTBS-1002,SE01002D,Woodinville,Jon Johnson
WTBS-1003,SE01003A,Bothell,Rob Roberts

These assignment values are comming from an Excel spreadsheet. I've done a copy from Excel then pasted into a notepad document, saved as ANSI text document, then FTP it to the Linux server (they initially show up as "
ASCII English text, with CRLF line terminators
"). The array lookup does not work in this state.

Next I modified the EOL (perl -pe 's/\r\n|\n|\r/\n/g') to make them "ASCII text". The array lookup does not work in this state.

If I copy the values from the notepad document and paste directly into a new document using vi, the array lookup does not work.

If I open the document in vi, delete a line, then retype the exact same values manually the array lookup works. Smilie

I have this exact same array lookup working properly in another directory (in that case the WBTSassignments1.txt file type is "ASCII text") but it was recently migrated from a HP Unix server (where it was originally created). If I run: od -c WBTSassignments1.txt on the working and non-working files I don't see a difference in formatting, nor do I see a difference when I manually add lines in vi (in all cases the the only special character is /n).

I'm missing something here but don't know what it is.

Thanks in advance.

---------- Post updated at 03:26 PM ---------- Previous update was at 01:54 PM ----------

To troubleshoot this I created two files:
a.txt where I copied the entire WBTSassignments.txt file and deleted everything but the first 4 lines.
Then I copied a.txt to b.txt, deleted the first 2 lines, then manually retyped them in vi.

If I compare the two files it recognizes a difference, but I'm not sure how to see exactly what the difference is outside of hex.


jhamm% cat a.txt
WTBS-1001,SE01001T,North Creek,George Becker
WTBS-1002,SE01002D,Woodinville - Sprint,Scott Winecoff
WTBS-1003,SE01003A,VSTREAM - Bothell 7,George Becker
WTBS-1005,SE01005F,Little BearCreek-Cooper,Scott Winecoff

jhamm% cat b.txt
WBTS-1001,SE01001T,North Creek,George Becker
WBTS-1002,SE01002D,Woodinville - Sprint,Scott Winecoff
WTBS-1003,SE01003A,VSTREAM - Bothell 7,George Becker
WTBS-1005,SE01005F,Little BearCreek-Cooper,Scott Winecoff

jhamm% sdiff a.txt b.txt
WTBS-1001,SE01001T,North Creek,George Becker | WBTS-1001,SE01001T,North Creek,George Becker
WTBS-1002,SE01002D,Woodinville - Sprint,Scott Winecoff | WBTS-1002,SE01002D,Woodinville - Sprint,Scott Winecoff
WTBS-1003,SE01003A,VSTREAM - Bothell 7,George Becker WTBS-1003,SE01003A,VSTREAM - Bothell 7,George Becker
WTBS-1005,SE01005F,Little BearCreek-Cooper,Scott Winecoff WTBS-1005,SE01005F,Little BearCreek-Cooper,Scott Winecoff


The look the same in octal.


jhamm% od -c a.txt
0000000 W T B S - 1 0 0 1 , S E 0 1 0 0
0000020 1 T , N o r t h C r e e k , G
0000040 e o r g e B e c k e r \n W T B
0000060 S - 1 0 0 2 , S E 0 1 0 0 2 D ,
0000100 W o o d i n v i l l e - S p
0000120 r i n t , S c o t t W i n e c
0000140 o f f \n W T B S - 1 0 0 3 , S E
0000160 0 1 0 0 3 A , V S T R E A M -
0000200 B o t h e l l 7 , G e o r g
0000220 e B e c k e r \n W T B S - 1 0
0000240 0 5 , S E 0 1 0 0 5 F , L i t t
0000260 l e B e a r C r e e k - C o o
0000300 p e r , S c o t t W i n e c o
0000320 f f \n
0000323

jhamm% od -c b.txt
0000000 W B T S - 1 0 0 1 , S E 0 1 0 0
0000020 1 T , N o r t h C r e e k , G
0000040 e o r g e B e c k e r \n W B T
0000060 S - 1 0 0 2 , S E 0 1 0 0 2 D ,
0000100 W o o d i n v i l l e - S p
0000120 r i n t , S c o t t W i n e c
0000140 o f f \n W T B S - 1 0 0 3 , S E
0000160 0 1 0 0 3 A , V S T R E A M -
0000200 B o t h e l l 7 , G e o r g
0000220 e B e c k e r \n W T B S - 1 0
0000240 0 5 , S E 0 1 0 0 5 F , L i t t
0000260 l e B e a r C r e e k - C o o
0000300 p e r , S c o t t W i n e c o
0000320 f f \n
0000323

[/code]

But there is a slight difference in hexadecimal.


jhamm% od -h a.txt
0000000 5457 5342 312d 3030 2c31 4553 3130 3030
0000020 5431 4e2c 726f 6874 4320 6572 6b65 472c
0000040 6f65 6772 2065 6542 6b63 7265 570a 4254
0000060 2d53 3031 3230 532c 3045 3031 3230 2c44
0000100 6f57 646f 6e69 6976 6c6c 2065 202d 7053
0000120 6972 746e 532c 6f63 7474 5720 6e69 6365
0000140 666f 0a66 5457 5342 312d 3030 2c33 4553
0000160 3130 3030 4133 562c 5453 4552 4d41 2d20
0000200 4220 746f 6568 6c6c 3720 472c 6f65 6772
0000220 2065 6542 6b63 7265 570a 4254 2d53 3031
0000240 3530 532c 3045 3031 3530 2c46 694c 7474
0000260 656c 4220 6165 4372 6572 6b65 432d 6f6f
0000300 6570 2c72 6353 746f 2074 6957 656e 6f63
0000320 6666 000a
0000323

jhamm% od -h b.txt
0000000 4257 5354 312d 3030 2c31 4553 3130 3030
0000020 5431 4e2c 726f 6874 4320 6572 6b65 472c
0000040 6f65 6772 2065 6542 6b63 7265 570a 5442
0000060 2d53 3031 3230 532c 3045 3031 3230 2c44
0000100 6f57 646f 6e69 6976 6c6c 2065 202d 7053
0000120 6972 746e 532c 6f63 7474 5720 6e69 6365
0000140 666f 0a66 5457 5342 312d 3030 2c33 4553
0000160 3130 3030 4133 562c 5453 4552 4d41 2d20
0000200 4220 746f 6568 6c6c 3720 472c 6f65 6772
0000220 2065 6542 6b63 7265 570a 4254 2d53 3031
0000240 3530 532c 3045 3031 3530 2c46 694c 7474
0000260 656c 4220 6165 4372 6572 6b65 432d 6f6f
0000300 6570 2c72 6353 746f 2074 6957 656e 6f63
0000320 6666 000a
0000323
# 2  
Old 11-13-2009
Apart from this one?

Code:
WTBS != WBTS

# 3  
Old 11-13-2009
Wow, I spent 8 hours troubleshooting a misspelling? That is about as good a reason as any to call it a week.

Works great now, thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

awk Associative Array and/or Referring to Field by String (Nonconstant String Value)

I will start with an example of what I'm trying to do and then describe how I am approaching the issue. File PS028,005 Lexeme HRS # M # PhraseType 1(1:1) 7(7) PhraseLab 501 503 ClauseType ZYq0 PS028,005 Lexeme W # L> # BNH # M #... (17 Replies)
Discussion started by: jvoot
17 Replies

2. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

3. Shell Programming and Scripting

Problem with lookup in awk

I need to add new ID to the file with old ID (column 7), I collected old ID / new ID pairs in a lookup file and I am trying to use awk to do the job, but something is not clicking. My input file ABC| 107|1440589221| -118.117167| 33.986333|10| 497476|1 ABC| 125|1440591215| -118.181000| ... (4 Replies)
Discussion started by: migurus
4 Replies

4. Shell Programming and Scripting

Using associative array for comparison

Hello together, i make something wrong... I want an array that contains information to associate it for further processing. Here is something from my bash... You will know, what I'm trying to do. I have to point out in advance, that the variable $SYSOS is changing and not as static as in my... (2 Replies)
Discussion started by: Decstasy
2 Replies

5. Shell Programming and Scripting

Awk: Dealing with whitespace in associative array indicies

Is there a reliable way to deal with whitespace in array indicies? I am trying to annotate fails in a database using a table of known fails. In a begin block I have code like this: # Read in Known Fail List getline < "'"$failListFile"'"; getline < "'"$failListFile"'"; getline <... (6 Replies)
Discussion started by: Michael Stora
6 Replies

6. Shell Programming and Scripting

Associative Array with more than one item per entry

Hi all I have a problem where i have a large list ( up to 1000 of items) and need to have 2 items pulled from it into variables in a bash script my list is like the following and I could have it as an array or possibly an external text file maintained separately. Every line is different and... (6 Replies)
Discussion started by: kcpoole
6 Replies

7. Shell Programming and Scripting

Associative array

I have an associative array named table declare -A table table="fruit" table="veggie" table="GT" table="eminem" Now say I have a variable returning the value highway How do I find corresponding value GT ?? (this value that I find (GT in this case) is supposed to be the name of a mysql... (1 Reply)
Discussion started by: leghorn
1 Replies

8. Shell Programming and Scripting

Help needed on Associative array in awk

Hi All, I got stuck up with shell script where i use awk. The scenario which i am working on is as below. I have a file text.txt with contents COL1 COL2 COL3 COL4 1 A 500 400 1 B 500 400 1 A 500 200 2 A 290 300 2 B 290 280 3 C 100 100 I could able to sum col 3 and col4 based on... (3 Replies)
Discussion started by: imsularif
3 Replies

9. Shell Programming and Scripting

awk, associative array, compare files

i have a file like this < '393200103052';'H3G';'20081204' < '393200103059';'TIM';'20110111' < '393200103061';'TIM';'20060206' < '393200103064';'OPI';'20110623' > '393200103052';'HKG';'20081204' > '393200103056';'TIM';'20110111' > '393200103088';'TIM';'20060206' Now i have to generate a file... (9 Replies)
Discussion started by: shruthi123
9 Replies

10. Shell Programming and Scripting

Associative Array

Hi, I am trying to make an associative array to use in a popup_menu on a website. Here is what i have: foreach $entr ( @entries ) { $temp_uid = $entr->get_value(uid); $temp_naam = $entr->get_value(sn); $s++; } This is the popup_menu i want to use it in. popup_menu(-name=>'modcon',... (4 Replies)
Discussion started by: tine
4 Replies
Login or Register to Ask a Question