Renaming multiples files with a bash loop

0 votes

I need to rename 45 files, and I don't want to do it one by one. These are the file names:

chr10.fasta         chr13_random.fasta  chr17.fasta         chr1.fasta          chr22_random.fasta  chr4_random.fasta  chr7_random.fasta  chrX.fasta
chr10_random.fasta  chr14.fasta         chr17_random.fasta  chr1_random.fasta   chr2.fasta          chr5.fasta         chr8.fasta         chrX_random.fasta
chr11.fasta         chr15.fasta         chr18.fasta         chr20.fasta         chr2_random.fasta   chr5_random.fasta  chr8_random.fasta  chrY.fasta
chr11_random.fasta  chr15_random.fasta  chr18_random.fasta  chr21.fasta         chr3.fasta          chr6.fasta         chr9.fasta         
chr12.fasta         chr16.fasta         chr19.fasta         chr21_random.fasta  chr3_random.fasta   chr6_random.fasta  chr9_random.fasta
chr13.fasta         chr16_random.fasta  chr19_random.fasta  chr22.fasta         chr4.fasta          chr7.fasta         chrM.fasta

I need to change the extension ".fasta" to ".fa". I'm trying to write a bash script to do it:

for i in $(ls chr*)

do

NEWNAME = `echo $i | sed 's/sta//g'`

mv $i $NEWNAME

done

But it doesn't work. Can you tell me why, or give another quick solution?

Thanks!

Jun 21, 2022 in Linux Administration by Korak
• 5,820 points
386 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Linux Administration

+1 vote
3 answers
0 votes
2 answers

how to loop through the content of a file using bash

#!/bin/bash for i in  `cat peptides.txt` do echo $i done READ MORE

answered Sep 5, 2020 in Linux Administration by Prakash K. Aithal
2,980 views
0 votes
1 answer

generating a list of files with their absolute path in Linux

If you find an absolute path to start with, ...READ MORE

answered May 16, 2019 in Linux Administration by Upasana
• 8,620 points
1,376 views
0 votes
1 answer

Select sections of text from each line of files in a Bash shell.

Hi@akhtar, There is no inbuild command available for ...READ MORE

answered Oct 20, 2020 in Linux Administration by MD
• 95,460 points
1,043 views
0 votes
0 answers

How do I run a program with commandline arguments using GDB within a Bash script?

When running a program on GDB, usually, ...READ MORE

Jun 21, 2022 in Linux Administration by Korak
• 5,820 points
717 views
0 votes
1 answer

setting a variable output from a bash command

You can use $(command), which in my ...READ MORE

answered Feb 15, 2019 in Linux Administration by DareDev
• 6,890 points
2,517 views
0 votes
1 answer

Script file name in a Bash script

$0 will give you the complete basename. ...READ MORE

answered Jun 20, 2019 in Linux Administration by Shubham
• 13,490 points
762 views
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 21, 2019 in Linux Administration by DareDev
• 6,890 points
939 views
0 votes
1 answer

Can I analyze a program's core dump file with GDB when it has command-line parameters?

You can simply use of GDB, to debug ...READ MORE

answered Jul 1, 2019 in Linux Administration by Shubham
• 13,490 points
8,075 views
0 votes
1 answer

How to create nested directories with a single command in linux?

Try this command. mkdir -p /parent_dir/son_dir READ MORE

answered Oct 19, 2020 in Linux Administration by anonymous
• 19,610 points
2,193 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP