move files of a different group to separate directory
You need to bring together the information in the two tables, I prefer R for such actions. The common columns between the two tables do not quite contain the same information hence additional data cleaning was required. Moreover the table with treatment information had to be changed to long format with melt. And I have filtered the merged_data so as to conation only "pretreatment" info but you can add a if/else statement to the for loop to control how/where you will move your files.

library(data.table)

clin_name &lt;- fread("clin_name.txt", header = TRUE)
clin_name$sample_id &lt;- sub("/E/T.", "", clin_name$sample_id)

pre_post &lt;- fread("pre_post.list", header = TRUE)
print(pre_post)
pre_post &lt;- melt(pre_post,
     measure.vars = c("pre-treated", "post-treated"),
     variable.name = "treatment",
     value.name = "sample_id")

&gt; print(pre_post)
      treatment sample_id
1:  pre-treated OC/AH/120
2:  pre-treated OC/AH/126
3:  pre-treated OC/AH/136
4:  pre-treated OC/AH/160
5: post-treated OC/AH/065
6: post-treated OC/AH/069
7: post-treated OC/AH/074
8: post-treated OC/AH/084


merged_data &lt;- merge(clin_name, pre_post)
print(merged_data)

pre &lt;- merged_data[merged_data$treatment == "pre-treated", "file_name"]

&gt; print(merged_data)
   sample_id         file_name   treatment
1: OC/AH/120 LP6005409-DNA_F01 pre-treated
2: OC/AH/126 LP2000325-DNA_A01 pre-treated
3: OC/AH/136 LP6005409-DNA_E02 pre-treated

# invoking a terminal command to move each file to a directory called "pre"
for (i in pre$file_name) {
  command &lt;- paste0("mv ", i, " pre/")
  system(command)
}