RELATED: Move all files with matching prefixes to folder based on a csv list
I have a two-column CSV file (comma-separated values), with headers:
"id","group"
"F1256","old"
"E51651","new"
"X56369","new"
"G5481369","old"
"54564564T","old"
"544-5F5","new"
"1298FFF","old"
"JKL-wew_w","new"
And I have these files in a single directory:
2014-12-15_T921_F1256.png
E51651_hf_2018-9-19.jpg
hf_oldX56369_15-10-2014.xml
2018-07_xx54564564T_hfdata.bmp
G5481369oldbackup_2018-01-01.txt
I want to use grep
(or any other similar tool) on these files, and match their filenames against the id
column of my CSV file. Upon a match (i.e. if id
is exactly found in the filename), the file has to be moved to the appropriate group
sub-directory.
Therefore, two folders, old
and new
must be created in the current directory and all those files must be moved according to the described condition.
RESULT
old
├──2014-12-15_T921_F1256.png
├──2018-07_xx54564564T_hfdata.bmp
├──G5481369oldbackup_2018-01-01.txt
new
├──E51651_hf_2018-9-19.jpg
├──hf_oldX56369_15-10-2014.xml
How can I do this?