renames files with the same folder name
1
0
Entering edit mode
4.5 years ago
AbdelAbdel ▴ 30

Hello, in short, I have folders and in each folder there is a file 'call < configs.fasta > and I wanted to get how I can rename the files with the same folder name. I've tried a for loop but it doesn't work.

 for i in *; do mv /*/contigs.fasta $i.fasta; done

Thank you for helping me

assembly rename • 1.2k views
ADD COMMENT
0
Entering edit mode

A small educational note: I added (code) markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

ADD REPLY
0
Entering edit mode

I understand why you might mask out the path your working in but i'm afraid the cause of your issue is likely caused by what's 'under' the * .

otherwise you can add in a dummy folder but at least we can then see what you try to do.

ADD REPLY
0
Entering edit mode

All right, thank you very much for the information.

ADD REPLY
0
Entering edit mode
4.5 years ago

input:

$ find . -maxdepth  2 -mindepth 2  -type f -name "contigs.fa"
./test2/contigs.fa
./test1/contigs.fa

dry-run

$ parallel --dry-run cp {} {//}.fa ::: $(find . -maxdepth  2 -mindepth 2  -type f -name "contigs.fa")
cp ./test2/contigs.fa ./test2.fa
cp ./test1/contigs.fa ./test1.fa

with bash:

tree .
.
├── test1
│   └── contigs.fa
└── test2
    └── contigs.fa

dry-run (remove echo):

$ find . -maxdepth  1 -mindepth 1  -type d | while read line; do echo mv $line/contigs.fasta $i.fasta; done

or

$ for i in $(ls -d */); do echo mv ${i%%/}/contigs.fasta ${i%%/}.fasta; done

mv ./test2/contigs.fasta test2.fasta
mv ./test1/contigs.fasta test2.fasta
ADD COMMENT
0
Entering edit mode

Thank you very much. I'll try you.

ADD REPLY

Login before adding your answer.

Traffic: 1604 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6