Question: 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

```

Answer: 
Based on your shown samples try following once. This is completely based on your shown attempt, since no samples were provided so its not tested, should work though.

```
#!/bin/bash
for index in {1..100}
do
   awk '/^MGD/{val=substr($1,4);if(val+0 >= 676 && val+0 <= 900){print}}' eq2_15_333_$index.ndx | tee eq3_15_333_$index.ndx
done

```
I want to explain why your original i.e.

```
awk 'BEGIN { FS = "MGD" }; {if ($2 >= 676 && $2 <= 900) print}'

```

did not work as excepted, you set `"MGD"` as `FS` thus AWK splitted only at `MGD` - if you do `awk 'BEGIN{FS="MGD"}{print $2}' file.txt` and content of `file.txt` is

```
MGD816 SOL77
MGD71 SOL117
MGD7 SOL13194
MGD18 SOL235
MGD740 SOL340
MGD697 SOL396
MGD70 SOL9910

```

output is

```
71 SOL117
7 SOL13194
18 SOL235
740 SOL340
697 SOL396
70 SOL9910

```

If you want `$2` to be first number you should specify `FS` which is `"MGD"` or spaces i.e.

`awk 'BEGIN{FS="MGD|[[:space:]]+"}`...