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
"what if I have many columns in the names.txt file and "TAr.gz_filenames" is 8th column and "Sample_Names" is 9th column. How to give the command?"
: this is also possible either withsed
orawk
orcut
or ... to select those columns and feed toxargs
. I see no such reason and difficulties shows that's different than what you asked already and got answer. – αғsнιη Apr 27 '18 at 16:19