About arrays in file 1 matching with file 2


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting About arrays in file 1 matching with file 2
# 1  
Old 05-13-2013
About arrays in file 1 matching with file 2

i have two files say a and b
a has these lines
Code:
1 20 30 40
2 30 40 50
3 25 35 45
5 20 50 20


and b has these lines


Code:
20 30 
30 40 
25 35 
20 50

the script reads
Code:
FILENAME ( "a" ) {
rec1[$1]=$2; rec2[$3]=$2; }
FILENAME ( "b" ) {
printf("%s %s\n",rec1[$1],rec2[$2]);
}



the result is
Code:
20 
30 20
25 
20 
30 20
40 30
35 25
50 20

It beats me, instead of four lines it gives me 8. where is the error?

Thanks in advance, for help


P N Doshi

Moderator's Comments:
Mod Comment Please use code tags!

Last edited by radoulov; 05-13-2013 at 01:09 PM..
# 2  
Old 05-13-2013
Hello paresh n doshi, what is the exact question? What output are you expecting?
# 3  
Old 05-13-2013
Since there are four record to match with array, the result I expect is four or less. But the awk returns 8 records, and I did not follow how. I had in mind the following result
Code:
   20
   30
   25
   20

for indexs $1 there are no matching values, where as for indexes $2 there are.

Can somebody help me solve this, pls

Last edited by paresh n doshi; 05-19-2013 at 02:38 AM.. Reason: for clarity sake
# 4  
Old 05-19-2013
Code:
FILENAME ( "a" ) {

should be:
Code:
FILENAME=="a" {

Presuming the two filenames you are using are "a" and "b"
# 5  
Old 05-19-2013
Thank you very much. The problem was elsewhere and my focus in some other place.
This changed set my problem right. Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace matching words defined in one file on another file?

I have file1 and file2 as shown below, file1: ((org14/1-131541:0.11535,((org29/1-131541:0.00055,org7/1-131541:0.00055)1.000:0.10112,((org17/1-131541:0.07344,(org23/1-131541:0.07426,((org10/1-131541:0.00201,org22/1-131541:0.00243)1.000:0.02451, file2: org14=india org29=america... (5 Replies)
Discussion started by: dineshkumarsrk
5 Replies

2. UNIX for Beginners Questions & Answers

awk to update file with partial matching line in another file and append text

In the awk below I am trying to cp and paste each matching line in f2 to $3 in f1 if $2 of f1 is in the line in f2 somewhere. There will always be a match (usually more then 1) and my actual data is much larger (several hundreds of lines) in both f1 and f2. When the line in f2 is pasted to $3 in... (4 Replies)
Discussion started by: cmccabe
4 Replies

3. Shell Programming and Scripting

awk to update file with sum of matching fields in another file

In the awk below I am trying to add a penalty to a score to each matching $1 in file2 based on the sum of $3+$4 (variable TL) from file1. Then the $4 value in file1 is divided by TL and multiplied by 100 (this valvue is variable S). Finally, $2 in file2 - S gives the updated $2 result in file2.... (2 Replies)
Discussion started by: cmccabe
2 Replies

4. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies

5. Shell Programming and Scripting

Shell script to filter records in a zip file that contains matching columns from another file

Not sure if this is the correct forum for this question. I have two files. file1.zip, file2 Input: file1.zip col1, col2 , col3 a , b , 0:0:0:0:0:c436:9346:d40b x, y, 0:0:0:0:0:880:39f9:c9a7 m, n , 0:0:0:0:0:80c7:9161:fe00 file2.txt col1 c4:36:93:46:d4:0b... (1 Reply)
Discussion started by: anil.v
1 Replies

6. UNIX for Dummies Questions & Answers

How to append portion of a file content to another file when a certain pattern is matching?

Hi ladies and gentleman.. I have two text file with me. I need to replace one of the file content to another file if one both files have a matching pattern. Example: text1.txt: ABCD 1234567,HELLO_WORLDA,HELLO_WORLDB DCBA 3456789,HELLO_WORLDE,HELLO_WORLDF text2.txt: XXXX,ABCD... (25 Replies)
Discussion started by: bananamen
25 Replies

7. Shell Programming and Scripting

Replace text in column1 of a file matching columns of another file

Hi all, I have 2 files: species-names.txt Abaca-bunchy-top-virus ((((Abaca-bunchy-top-virus((Babuvirus((Unassigned((Nanoviridae((Unassigned)))) Abutilon-mosaic-virus ((((Abutilon-mosaic-virus((Begomovirus((Unassigned((Geminiviridae((Unassigned))))... (2 Replies)
Discussion started by: thienxho
2 Replies

8. Shell Programming and Scripting

awk - writing matching pattern to a new file and deleting it from the current file

Hello , I have comma delimited file with over 20 fileds that i need to do some validations on. I have to check if certain fields are null and then write the line containing the null field into a new file and then delete the line from the current file. Can someone tell me how i could go... (2 Replies)
Discussion started by: goddevil
2 Replies

9. Shell Programming and Scripting

Want to read data from a file name.txt and search it in another file and then matching...

Hi Frnds... I have an input file name.txt and another file named as source.. name.txt is having only one column and source is having around 25 columns...i need to read from name.txt line by line and search it in source file and then save the result in results file.. I have a rough idea about the... (15 Replies)
Discussion started by: ektubbe
15 Replies

10. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies
Login or Register to Ask a Question