| Ed Morton 2004-11-16, 6:50 pm |
|
Micha³ wrote:
> Hi I've just started to learn awk and I have a question. I can write very
> simple scripts but this task I think is too difficult for me.
> I have two input files
> First contains data as follows separated with " "
> 1 1
> 1.12 2
> 1.13 4
> 1.24 5
> and second file contains similar data :
> 1.02 1
> 1.13 2
> 1.20 3
> 1.28 5
> This files are very big and I want to:
> Compare fields in the second columns and if fields are equal I want awk to
> substr
ITYM "subtract" not "substr".
field from first column of second file with first column of first
> file.
> So this script should do. Get first field in second column in second file,
ITYM Get the second field in the first line in the second file.
> search for the same field in second column first file and if they are equal
> substr
ITYM "subtract" not "substr".
fields in first columns.If they aren't equal search in next field
ITYM If ther aren't equal search in the next line
> For this example I gave awk should produce:
> 0.2 1
> 0.01 2
> 0.04 5
>
> Tkanks for any answers
I assume the values in the second column of file2 are unique and that if
they aren't unique in file1 you want the same operation applied to all.
If all my assumptions above are correct, then this should so it (untested):
awk 'NR==FNR{f1[$2]=$1;next}
$2 in f1{$1=$1-f1[$2];print}' file2 file1
Regards,
Ed.
|