I've got directories with multiple files so that they're generally in the format:
dir1/identifier1_desiredName1.m
dir1/identifier1_desiredName2.m
dir1/identifier2_desiredName1.m
dir1/identifier2_desiredName2.m
dir1/identifier3_desiredName1.m
dir1/identifier3_desiredName2.m
dir1/other--should-not-be-moved
dir2/identifier1_desiredName1.m
dir2/identifier1_desiredName2.m
dir2/identifier2_desiredName1.m
dir2/identifier2_desiredName2.m
dir2/identifier4_desiredName1.m
dir2/identifier4_desiredName2.m
dir2/jabberwocky-mimsy-borogoves
I'm trying to come up with a script that separates the files by the identifier by making a directory using that identifier, and then moves files with the same identifier into that directory. As of right now, I think that I'm on the right track for the directory making:
awk _ {print $1} | uniq | mkdir
Syntax probably isn't quite correct, but the general idea is to print out the first column, separated by _, omitting repeats, and then piping those names into mkdir. But then I'm at a loss for moving the files into the directories. I was thinking about using grep similarly (replacing mkdir above), but I wasn't sure if it would work.