Create Symlinks from file list - PART 2
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

DISCLAIMER: I had a similar question and was thankfully answered here (https://bountify.co/linux-fix-multiple-broken-symlinks) solution.

I have a list of multiple files where they are located.
Each file has a different uuid_1 and uuid_2 number.

The list with the original file location structure is: /UUID_NUMBER1/UUID_NUMBER2/NAME_OF_THE_FILE

The list with the original files looks like this:

/mnt/archive/d8e15eda-x5xe-454b-9def-37dd54ed05cc/944c8f69-be2a-47ff-b18b-706a71cab85d/ABC_DE__FGGHJ20020526_152812_000050022006_00183_01239_0001.N1
/mnt/archive/05646772-5c99-423d-aaf4-cc571fa35f90/b23b9aa0-8830-47c9-9a78-f5ead3547186ABC_DE__FGGHJ20070912_170334_000053152006_00184_01240_0001.N1
/mnt/archive/61bdad3c-c718-4036-918b-2b4f5cd1453e/75559161-d96d-4def-af98-eeb87542f5f0/ABC_DE__FGGHJ20090526_169723_000056712006_00185_01241_0001.N1

The symlink needs to be created (after deleting the broken symbolic link) in the structure /YEAR/MONTH/DATE/NAME_OF_THE_FILE order that can be seen forming part of the filename: ABC_DE__FGGHJ20020526_152812_000050022006_00183_01239_0001.N1

portion with the date: FGGHJ20020526

date as in folder structure: /2002/05/26/

Example:

/mnt/example/FOLDER_1/master/2002/05/26/ABC_DE__FGGHJ20020526_152812_000050022006_00183_01239_0001.N1

A way to extract the structure was explained here: https://stackoverflow.com/questions/65332507/extract-path-from-filename using sed (can also be done with awk)

Ideally, I need to read from the list of files, extract the folder structure where the link needs to be created, delete the broken link and create the link in that folder.

awarded to Dudu

Crowdsource coding tasks.

1 Solution

Winning solution

I manage to solve it by finding all the files in each uuid folder and copy them to 1 specific folder in which each can be linked separately. So not the direct link to the original location I was looking for but it works