Skip to main content
Formatting; Re-tag (post didn't contain any reference to specific text-processing tools; is unrelated to "find" tool; but describes typical shell-script task)
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

I have a list of paths stored in a shell variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar
/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar
/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar
/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R1.tar
/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R2.tar
/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directories  ZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, , S2_L001_I1.tar, and , and S1_L001_I2.tar

How do I achieve this?

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

I have a list of paths stored in a shell variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar
/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar
/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar
/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R1.tar
/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R2.tar
/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directories  ZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

Edited directory structure to make it uniform and less complex
Source Link

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/asd/hrt/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/asd/agf/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/asd/sdc/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/asd/hrt/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/asd/agf/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/asd/sdc/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

Edited: Create soft links instead of move
Source Link

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/asd/hrt/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/asd/agf/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/asd/sdc/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and move allcreate soft links for the tar files into thetheir corresponding directorydirectories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/asd/hrt/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/asd/agf/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/asd/sdc/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and move all the tar files into the corresponding directory.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

I have a list of paths stored in a variable tmp for example:

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_R1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S2_L001_I1.tar

/abc/bcd/def/ZRT834/ZRT834_9/5678/S1_L001_I2.tar

/abc/bcd/def/asd/hrt/ZRT207/ZRT207_1/5678/S1_L001_R1.tar

/abc/bcd/def/asd/agf/ZRT207/ZRT207_1/5678/S1_L001_R2.tar

/abc/bcd/def/asd/sdc/ZRT207/ZRT207_1/5678/S1_L001_I2.tar

I want to create new directories based on the matching patterns from the paths. In the above example, I want to create directoriesZRT834_9 and ZRT207_1 and create soft links for the tar files into their corresponding directories.

My output should be something like: ZRT834_9 directory having S1_L001_R1.tar, S2_L001_I1.tar, and S1_L001_I2.tar

How do I achieve this?

Edited the input paths
Source Link
Loading
Source Link
Loading