Thursday, May 16, 2024
0
rated 0 times [  0] [ 0]  / answers: 1 / hits: 1678  / 1 Year ago, wed, january 18, 2023, 1:33:38

I am new learner of Linux - Ubuntu. I need to rename a large number of files (keeping same extension) corresponding to a list of names in a file. I have a list of names in a text file.


For example


Current filename => New filename


GCA_001340506.1_ASM54621.fna => wax.fna


GCF_0133435.1_ASM4354653.fna => strains2213.fna


I need to rename current filename with the new filename. As we can see, I need two things first to match the corresponding filename and then rename it.


I cannot find a proper way to complete this task. Kindly help me in this regard.


Awan


More From » command-line

 Answers
7

I created the following function.
you have to use in this way:


$ furqan_mv filenames.txt


the file filenames.txt must have the following format:


oldfile => newfile


the extension is always fna.
Here is the function:


furqan_mv() {
ext=".fna"
while IFS= read -r line; do
oldfile=`echo $line | awk '{print $1}'`
newfile=`echo $line | awk '{print $3}'`
mv $oldfile.$ext $newfile.$ext
done < $1
}

[#2574] Wednesday, January 18, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itutejagua

Total Points: 89
Total Questions: 124
Total Answers: 113

Location: British Indian Ocean Territory
Member since Sun, Feb 13, 2022
2 Years ago
itutejagua questions
;