I have three files, a, b, and c. c has has a list of codes. b has two columns: a column of codes and their corresponding test name. The last file, a, has a list of names which contain (as substrings) all test names. Examples:
c:
codeb coded codea codec codee codef codee codeg codehb:
codea testa codeb testb codec testc coded testa codee testa codef testb codeg testc codeh testaa:
testa1234 testb21345 14231testcAr
I want to output the corresponding name in a file for each code in c. For example, codeb should output testb21345. I haven't been able to make it work. I think this has to do with grep not understanding the pattern. This is the loop I have written as MVE:
diractual=$PWD
while read line; do
ca=$(grep $line $diractual/b | cut -f 2)
ca_complete=$(grep $ca $diractual/a)
echo "This is ca:"
echo "$ca"
echo "This is ca_complete:"
echo "$ca_complete"
done <$diractual/c
The two echos should output, for example for codeb (the first line in c):
This is ca:
testb
This is ca_complete:
testb21345
But it outputs (for every line):
This is ca:
testb
This is ca_complete:
#(Empty line)
So the first grep is finding the correct test and it is storing it in variable ca but the second one is not finding this pattern in a.
ca_completeyou're greping fromcagain, don't you mean to get it froma?bhave carriage returns at the end of it perhaps?