I have a simple command like this
grep 'X' results.dat | awk '{print $NF}' > Y.dat
I want to loop this command taking the Xs from column 1 and the corresponding Ys from column 2 of the same file eg. NAMES
NAMES file has the format
C11-C12 p01
C13-C14-C17 P02
etc ..
so the first two steps in the loop should be like this
grep 'C11-C12' results.dat | awk '{print $NF}' > p01.dat
grep 'C13-C14-C17' results.dat | awk '{print $NF}' > p02.dat