Hello MDeBiasse,
If I caught your logic correctly then last line should be X 6 X
Following may help you in same. Please let me know if this helps.
awk -vs1=`cat Input_file | wc -l` 'BEGIN{print "A" OFS "B" OFS "C"} FNR==NR && NR>1{A[$1];B[$2];C[$3];next} END{o=1;for(k=1;k<=s1;k++){S=(k in A)?o:"X";U=(k in B)?o:"X";V=(k in C)?o:"X";print S OFS U OFS V;S=U=V="";o++}}' Input_file Input_file
Where input_file is as follows:
A B C
1 1 2
2 3 3
3 4 5
4 6
5
Output will be as follows.
A B C
1 1 X
2 X 2
3 3 3
4 4 X
5 X 5
X 6 X
EDIT: Seems moderator has modified post now by adding code tags, thank you for same. Then Following is the input file per user.
Input_file:
cat testtest13
A B C
1 1 2
2 3 3
3 4 5
4 6
5
Then following code may help.
awk -vs1=`cat testtest13 | wc -l` -F" " 'BEGIN{print "A" OFS "B" OFS "C"} FNR==NR && NR>1{sub(/[[:space:]]/,X,$1);sub(/[[:space:]]/,X,$2);sub(/[[:space:]]/,X,$3);A[$1];B[$2];C[$3];next} END{o=1;for(k=1;k<=s1;k++){S=(k in A)?o:"X";U=(k in B)?o:"X";V=(k in C)?o:"X";print S OFS U OFS V;S=U=V="";o++}}' testtest13 testtest13
Output will be as follows.
A B C
1 1 X
2 X 2
3 3 3
4 4 X
5 X 5
X X 6
EDIT: Adding a non one liner form for solution following.
awk -vs1=`cat testtest13 | wc -l` -F" " 'BEGIN {print "A" OFS "B" OFS "C"}
FNR==NR && NR>1 {sub(/[[:space:]]/,X,$1);
sub(/[[:space:]]/,X,$2);
sub(/[[:space:]]/,X,$3);
A[$1];
B[$2];
C[$3];
next
}
END {o=1;
for(k=1;k<=s1;k++){
S=(k in A)?o:"X";
U=(k in B)?o:"X";
V=(k in C)?o:"X";
print S OFS U OFS V;
S=U=V="";
o++
}
}
' testtest13 testtest13
Thanks,
R. Singh