sorting and moving a bunch of fasta files into separate folder
1
0
Entering edit mode
19 months ago

Hi guys,

I have 1000s of MAGs fasta files in a single folder. So I wanted to move only a few groups of MAGs into a separate folder. So I have listed all the files (e.g., GCA_003221885.fa) one by one that I need to move in a txt file called HQ_MAGS.txt which is in the directory /home/venkat/Gemmatimonadota

So, if I wanted to move the listed files into this directory /home/venkat/Gemmatimonadota/HQ

How I do that using bash?

Many thanks
Venkat

fasta bash • 1.3k views
ADD COMMENT
1
Entering edit mode

While it is tempting to ask for ready solutions it is more fun to search/experiment. This is the only way you will learn. Since we can't see your data/file/folders (and the question is not clear) you may not get great answers.

It sounds like you have a list of files you want to selectively move into a folder. So walk through the file in a for loop and then simply mv that_file /home/venkat/Gemmatimonadota/HQ. I will leave you to find the specific answer.

ADD REPLY
0
Entering edit mode

thanks for your reply i did try using loop , but unfortunately it didn work out. here is the command that i used.

for file in cat HQ_MAGS.txt; do mv "$file" /home/venkat/Gemmatimonadota/HQ; done

clarity on my question:

I have bunch of fasta files in the HQ_MAGS.txt see below

GCA_003221885.fa GCF_014202995.fa GCA_029262115.fa GCA_027593165.fa GCA_022571515.fa GCA_016873995.fa GCF_000695095.fa GCA_028278645.fa

any help would be much appreciated

ADD REPLY
1
Entering edit mode
for file in `cat HQ_MAGS.txt`; do echo mv ${file} /home/venkat/Gemmatimonadota/HQ; done

You appear to be missing back-ticks around the cat command. Try the command above. If all command lines (that will be simply printed to screen) look right, then remove the word echo to actually move the files.

Note: This will only work if you have one file name per line in MAGs file and the files to be moved are in the directory where you are running this from.

ADD REPLY
0
Entering edit mode

Please use Google to understand how to use tags. Don't copy paste the title into the tags field, use keywords. I've fixed it for you this time.

ADD REPLY
1
Entering edit mode
19 months ago

Banish bash for loops from your life! You'll be happier and more productive.

When someone needs to operate on the content of a file, the best tools are xargs available by default (and parallel needs installation)

cat filelist.txt | xargs -n 1 -I {} echo mv {} your/new/path/{}

or

cat filelist.txt | parallel echo mv {} your/new/path/{}

Your best bet is to play it safe and print the commands instead of performing the move, that way you can check what it tries to do.

Investigate the commands, and they look ok then rerun while piping the output through bash

cat filelist.txt | xargs -n 1 -I {} echo mv {} your/new/path/{} | bash
ADD COMMENT
0
Entering edit mode

Thanks a lot for the input

ADD REPLY
0
Entering edit mode

You don't need to use cat if you do

xargs -a filelist.txt -n 1 -I {} echo mv {} your/new/path/{}
ADD REPLY
0
Entering edit mode

I don't think one needs -n 1 with -I as -I seems to automatically use -n 1 for content separated by newline:

-I replstr: Execute utility for each input line

-n number: Set the maximum number of arguments taken from standard input for each invocation of utility.

ADD REPLY

Login before adding your answer.

Traffic: 1822 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