I have two text files. hash_only.txt and final_output.txt hash_only.txt looks like below.
193548
401125
401275
final_output.txt looks like below.
193548 1199687744 5698758206701808640
193548 1216464960 5698758206761818112
193548 1216464960 5698758206778417152
193548 4236691520 5698758206778945280
401125 2138607488 5698762375908890880
401125 863932288 5698762375909423360
401125 3884158848 5698762375910044160
401125 2609483648 5698762375911032320
I am trying to write a loop which does the follows.
for i in `cat hash_only.txt` ;
do
for j in `cat final_output.txt` ;
do
if [ $i -eq $j ]
then
echo $i $j
fi
done
done;
For all the values in hash_only.txt such as 193548,401125 etc I want to extract column 2,3 from the file 'final_output.txt' where column 1 matches 193548,401125 etc and output column 2,3 to print_193548, print_401125 etc.
How do I do that.In the above code I need to put some code inside the then part.But I can't figure that out since I am not very proficient in bash.
Edit:
I have now modified the my script to look likefor i in cat hash_only.txt ;
do
for j in `cat final_output.txt` ;
do
if [ $i -eq $j ]
then
gawk 'FNR==NR
{ hash[$1]
next
}
$1 in hash {
print $2,$3 >> "print_"$1;
}' hash_only.txt final_output.txt
fi
done
done;
It is not creating any files named print_[0-9]*.I can't understand why not?
gawkcommand will do all the job.if...else/for...loopcan be deleted.