I CAN generate this 3.txt output
AA;BB;CC;DD;
from 2 text files. Both files only have a single record
1.txt
AA;BB;
2.txt
CC;DD;BB;AA;
I use this awk script.
BEGIN{
FS=OFS=";"
}
{
for(i=1;i<=NF;i++){
if(!seen[$i]++){ val=(val?val OFS:"")$i }
}
print val
delete seen
val=""
}
I use in this way, I use paste command to combine both the files and then processing its output by awk command.
paste 1st.txt 2nd.txt | awk -f tst.awk > "3.txt"
But what I want?
I need to consider more of one single record. I try to adapt this script for this situation. You can see that now both files have not only a single records.
1.txt
UU;
AA;BB;
ZZ;KK;
2.txt
CC;DD;BB;AA;
LL;KK;
GH;ZZ;SS;
output 3.txt that I try to generate is this
UU;
AA;BB;CC;DD;
ZZ;KK;LL;GH;SS;
processing logic:
Code above just uses literal strings in a hash lookup of array indices so it doesn't care what characters you have in your input.
However about sample output: if in 2.txt there are common fields also in 1.txt.for example BB;AA; then you need concatenate them in a single row, i.e AA;BB;CC;DD; Ordering is not required, for example is not relevant if output is BB;AA;DD;CC; Only condition that is required is avoid duplicates fields in the same row
When I say 'avoid duplicates' I mean avoid this output
AA;BB;CC;DD;BB;AA;
because output should be
AA;BB;CC;DD;