I have hundreds of text files in a folder named using this kind of naming convention:
Bandname1 - song1.txt
Bandname1 - song2.txt
Bandname2 - song1.txt
Bandname2 - song2.txt
Bandname2 - song3.txt
Bandname3 - song1.txt
..etc.
I would like to create folders for different bands and move according text files into these folders. How could I achieve this using bash, perl or python script?
gregseth‘s answer will work, just replace
trimwithxargs. You could also eliminate theiftest by just usingmkdir -p, for example:Strictly speaking the
trimorxargsshouldn’t even be necessary, butxargswill at least remove any extra formatting, so it doesn’t hurt.