Dynamic Column with Text Match

Question

How can Awk be used to find values that match row 1 for each column?

I would like to take in a tab-limited file and for each column if any row below row 1 matches what is in row 1, print field with "match".

Transform this tab-delimited file:

header1   header2   header3

1     1     B

3     1     A

2     A     B

1     B     1

 

To this:

header1   header2   header3

1     1     B

3     1 match   A

2     A     B match

1 match   B     1

 

Answer

In this case it’s easier to perform judgement in SPL than in Awk. You can execute an SPL script at command line or integrate it with a Java application (About the integration, see How to Call an SPL Script in Java).

A

1

=   file("user/data.txt").import@t()

2

=A1(1).array()

3

=A1.to(2,).run(~.record(~.array().(if(~==A2(#),~/"match",~))))

A1: Import data.txt.

undefined

A2: Return field values of A1’s first row as a sequence.

A3: Beginning from A1’s 2nd row, match each field value with that in the same position in A2.

undefined