From: Moody on
awk '
NR==FNR && $10 ~ !/null/ {
if ( length($10)==14 )
$10=substr($10,3);
x[$10]=$10;
next;
}
FNR!=NR {
b=$2;
if ( b in x) {
print $0
}
} ' file1 file2 > file3

file1's 10th column is baseline and I need to verify $0 from file1 in
file2 and print matched line in file3

Thanks
From: Janis Papanagnou on

Please try to create a sensible posting if you want people to help you.

Moody wrote:
> awk '
> NR==FNR && $10 ~ !/null/ {
> if ( length($10)==14 )
> $10=substr($10,3);
> x[$10]=$10;
> next;
> }
> FNR!=NR {
> b=$2;
> if ( b in x) {
> print $0
> }
> } ' file1 file2 > file3
>
> file1's 10th column is baseline and I need to verify $0 from file1 in
> file2 and print matched line in file3
>
> Thanks
From: Moody on
I want to extract 10th column from file1 and compare it to 2nd column
in file2, if that matches, I want to write that line combined in a
thrid file

file1:

1 2 3 4 5 6 7 8 9 10 11 2 3 4 12 5 6 767 435 7 678 123
34 45 567 67 8 789 890 808 09 34 432 34 232 43 5 7 687
54 5456 8 7 33 2 4 4546 5 58 68 9 4 45 3234 233 42 34

file2:

CUSTOM_VALUE 10
CUSTOM1_VALUE 34
CUSTOM2_Value 58


Output file3:

1 2 3 4 5 6 7 8 9 10 11 2 3 4 12 5 6 767 435 7 678 123 CUSTOM_VALUE
34 45 567 67 8 789 890 808 09 34 432 34 232 43 5 7 687 CUSTOM1_VALUE
54 5456 8 7 33 2 4 4546 5 58 68 9 4 45 3234 233 42 34 CUSTOM2_Value


Regards,
BB


From: pk on
Moody wrote:

> I want to extract 10th column from file1 and compare it to 2nd column
> in file2, if that matches, I want to write that line combined in a
> thrid file
>
> file1:
>
> 1 2 3 4 5 6 7 8 9 10 11 2 3 4 12 5 6 767 435 7 678 123
> 34 45 567 67 8 789 890 808 09 34 432 34 232 43 5 7 687
> 54 5456 8 7 33 2 4 4546 5 58 68 9 4 45 3234 233 42 34
>
> file2:
>
> CUSTOM_VALUE 10
> CUSTOM1_VALUE 34
> CUSTOM2_Value 58
>
>
> Output file3:
>
> 1 2 3 4 5 6 7 8 9 10 11 2 3 4 12 5 6 767 435 7 678 123 CUSTOM_VALUE
> 34 45 567 67 8 789 890 808 09 34 432 34 232 43 5 7 687 CUSTOM1_VALUE
> 54 5456 8 7 33 2 4 4546 5 58 68 9 4 45 3234 233 42 34 CUSTOM2_Value

Try:

awk 'NR==FNR{a[$2]=$1;next} $10 in a{print $0 FS a[$10]}' file2 file1 >file3

From: Alan Curry on
In article <a3f166f0-c478-457e-bc49-a7e560af5b96(a)v29g2000prb.googlegroups.com>,
Moody <nasir.mahmood(a)gmail.com> wrote:
>I want to extract 10th column from file1 and compare it to 2nd column
>in file2, if that matches, I want to write that line combined in a
>thrid file

join -1 10 -2 2 file1 file2

See join(1)
--
Alan Curry