I want to delete all lines in which MGD is not between 676 and 900. I wrote a script
#!/bin/bash
for index in {1..100} # I do this script on 100 files, that is why I use for loop
do
awk 'BEGIN { FS = "MGD" };
{if ($2 >= 676 && $2 <= 900) print}' eq2_15_333_$index.ndx | tee eq3_15_333_$index.ndx
done
Input example
MGD816 SOL77
MGD71 SOL117
MGD7 SOL13194
MGD18 SOL235
MGD740 SOL340
MGD697 SOL396
MGD70 SOL9910
Expected output
MGD816 SOL77
MGD740 SOL340
MGD697 SOL396
I don't know what my script do something wrong, because I still have something which has MGD7 or MGD71, but MGD18 I haven't in my output.
Edit
I tested this script and it works perfectly
awk '/^MGD/{val=substr($1,4);if(val+0 >= 676 && val+0 <= 900){print}}' new.txt | tee new2.txt
and I have output
MGD816 SOL77
MGD740 SOL340
MGD697 SOL396