Matching text in a list of files
by Entropy1024 from LinuxQuestions.org on (#4ZV70)
Using a Bash script I want to create a folder if there is more than one matching occurrence of text in a filename, then move those matching files to that folder. This is to organise TV shows into folders. ie if in the 'to sort' folder I have the following files:
Code:mr.robot.1080p.s01e01.mkv
mr.robot.1080p.s01e02.mkv
HD.dark.s02.e10.720p.mkv
HD.dark.s02.e11.720p.mkv
30.rock.s02e02.mkv
8.days.s01e01.mkvIn the example above it would like to create the following 2 folders:
Code:mr.robot.1080p.s01e
HD.dark.s02.e1Obviously in an ideal world it would truncate the folders to
Code:mr.robot
darkHowever I think I can get that part of the script working. I'm just unsure how to search for a matching set of text within the filename. In fact I would probably strip the filenames of things like 1080P, HD, sxx, exx etc before checking for a match.
Many thanks for any help.


Code:mr.robot.1080p.s01e01.mkv
mr.robot.1080p.s01e02.mkv
HD.dark.s02.e10.720p.mkv
HD.dark.s02.e11.720p.mkv
30.rock.s02e02.mkv
8.days.s01e01.mkvIn the example above it would like to create the following 2 folders:
Code:mr.robot.1080p.s01e
HD.dark.s02.e1Obviously in an ideal world it would truncate the folders to
Code:mr.robot
darkHowever I think I can get that part of the script working. I'm just unsure how to search for a matching set of text within the filename. In fact I would probably strip the filenames of things like 1080P, HD, sxx, exx etc before checking for a match.
Many thanks for any help.