I have many tar.gz files in a folder on my Linux machine and also text file with tar.gz file names and matching sample names.
Current_directory |_______TDF.tar.gz |_______DFG.tar.gz |_______GHY.tar.gz
names.txt file which is in current directory looks like below:
Tar.gz_filenames Sample_Names DFG.tar.gz Sample2 TDF.tar.gz Sample1 GHY.tar.gz Sample3
So, based on their match I want the following output in my Current_directory.
Output: Sample1.tar.gz Sample2.tar.gz Sample3.tar.gz
I tried like following but didn't work:
for j in .tar.gz ; do sed "s/\(\w\+\)\s\+\(\w\+\)/mv '*_\1$j' '*_\2$j'/e" names.txt done
Small update in my question: When I used this command
cat -e names.txt I see like following:
Tar.gz_filenames Sample_Names^M$ DFG.tar.gz Sample2^M$ TDF.tar.gz Sample1^M$ GHY.tar.gz Sample3