1

I have lots of files all of which are similar to the following:

frame1_M.png
frame1_S.png
frame1_L.png
frame1_N.png
frame1_D.png
frame1_M.png
frame1_S.png
frame1_L.png
frame1_N.png
frame1_D.png
frame2_M.png
frame2_S.png
frame2_L.png
frame2_N.png
frame2_D.png
frame3_M.png
frame3_S.png
frame3_L.png
frame3_N.png
frame3_D.png

How can I put all the items of frame1 in a directory made in the current directory named frame1, same goes with frame2 and rest of frames. As you see, in each group of files, only the frame number is common.

This is just an example. The files are in the range of 30k so needs to be done with terminal/bash. *Frame numbers are totally random in the real scenario not ordered so that makes it a very challenging task for me.

  • Create a bash script, a simple for and find command will do the work I guess. – Ravexina Apr 10 '17 at 23:30
  • You have inconsistent input: you've two files frame1_L.png and there's other duplicates,too. – Sergiy Kolodyazhnyy Apr 11 '17 at 1:18
0

_adb:

for q in *.png; do mkdir -p "${q%_*}"; mv "$q" "${q%_*}"; done

From #bash IRC channel! Thanks a lot _adb! Works like magic!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.