Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

processing two files at the same time

Status
Not open for further replies.

isahak

Programmer
Dec 12, 2007
3
Hi all
I have a question about processing two files at the same time.
For example
one file is for the first store(store #1)

Name Hrs
Jhon 22 Pay rate is $10
Adam 21
Kathy 23

Another file is for the second store(store #2)

Name Hrs
Jhon 20
Kathy 20 pay rate is $11
ALex 19

As you can see, both stores have, some common and some different employees, So, I need to do the calculation on both files at the same time.

Now how do I calculate their pay check.

For example, the output would be
Jhon 440
Adam 210
Kathy 450
Alex 209

Should I read both of the files, in the 'BEGIN' block, and calculate in the 'END' block. or is there any thing else I can do.


Thanks
 
Why don't you read file1 into an array, and then process the second one:

Code:
#!/bin/ksh

nawk ' BEGIN { cnt=0;
   while ( getline line < "file1" > 0 )
      {
      n[$1]=$2
      cnt++
      }
}
{
# do your processing with the array
print $0
} ' file2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top