I have one text file that stores all the criteria and I have another text file which is criteria assigned to one person. So this is all the criteria stored: criteria.txt
criteria1|desc1|3
criteria2|desc2|4
criteria3|desc3|4
criteria4|desc4|3
criteria5|desc5|5
And this is the criteria assigned to a person: criteria2.txt
criteria2|desc2|4
criteria1|desc1|3
criteria3|desc3|4
I want to display the criteria assigned to the person from criteria2.txt according to the criteria.txt sequence like this:
criteria1 #instead of criteria2
criteria2 #instead of criteria1
criteria3 #instead of criteria3
I tried the coding below but it prints nothing.
while IFS='|' read -r var1 var2 var3
do
grep "$var1" criteria2.txt | cut -f1 -d "|"
done < criteria.txt
Edit:
I use this command
awk -F'|' '{print $1} criteria2.txt | sort
and the problem is solved but this only sort by the first variable.