it would be great if someone can help me with the following:
I want to search for the rows from fileA in column 1 of fileB and output column 2 of fileB if found in fileC. In the moment I search within the complete file. How can I change the code so only column 1 is searched?
cat fileA | while read row ; do
grep "$row" fileB | awk -F"\t" '{print $2}' > fileC
The horizontal tab (\t) is already a default field separator, so unless you plan to explicitly count fields using it there's no need to specify it with -F.
=1 is just to record that the value of the record ($0) from the first file (FR==FNR) has been stored. This is used later (A[$1]) to test against the first field of the second file, in which case $2 from that file is displayed.
Hi Scott, thanks again for your help! I finally figured it out - found a very simple solution: I just had to add an ^ before "$row" to only search within the first column..
cat fileB | while read row ; do grep ^"$row" fileA | awk -F"\t" '{print $2}' > fileC