Wednesday, April 13, 2022

[SOLVED] Regex for moving based on last 4 digit combinations in a file

Issue

I have files which are labelled in the following manner, and need to move them according to 0000 - 0010 (base the last 4 digits. What is the regex for this? I have tried this regex but I don't get anything. As someone who isn't an expert on regex any help would be appreciated.

find ./ -regextype egrep -regex '.*file([0-9]\+-[0-9]\+-[0-9])\+.flac'

I get no output from my regex, but would like to copy only 0000 to 0010 to a new location

1241-137614-0000.flac
1241-137614-0001.flac
1241-137614-0002.flac
1241-137614-0003.flac
1241-137614-0004.flac
1241-137614-0005.flac
1241-137614-0006.flac
1241-137614-0007.flac
1241-137614-0008.flac
1241-137614-0009.flac
1241-137614-0010.flac

Solution

I suggest with bash version >= 4.0:

mv 1241-137614-{0000..0010}.flac <destination_dir>

If a source file does not exist, you will get an error message from mv.



Answered By - Cyrus
Answer Checked By - Pedro (WPSolving Volunteer)