I am dealing with management of big number of filles having fixed structure of the name, in multi-column format separated by \_:

```
3000_12_lig_cne_158.dlg
1300_10_lig_cne_983.dlg
4000_09_lig_cne_158.dlg
5000_09_lig_cne_158.dlg
7000_09_lig_cne_158.dlg
10V1_06_lig_cne_983.dlg
10V2_11_lig_cne_158.dlg
N000_12_lig_cne_158.dlg
M000_10_lig_cne_158.dlg
E000_10_lig_cne_158.dlg

```

So the first column can contain either four numbers (like 7000) or combination of the numbers and letters (like N000 or 10V1).

Using some bash routine I have to sort all of those filles according to the first column name, creating for each repertoire sub-directory matched the name of the first column. So for the list of the demonstrated filles totally 10 directories (3000, 1300, E000, M000, 10V1, 10V2 etc) should be created.

For the filles having only digital number in the first column I can use the following rouring, which uses regular expression in FOR loop to sort the filles.

```
for i in ${FILES}/[0-9]*_*.dlg        # match the filles containing only digits in the first column
do 
    j=${i##*/}               # strip the path off from beginning to last /
    mkdir -p $OUTPUT/${j%%_*}        # create dir with the name matching the first column of the file
    mv $i $OUTPUT/${j%%_*} # move the file to the corresponded directory
done

```

How I could modify it to match all of the demonstrated patterns of the first column ?