Thanks a lot for the input
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
1 answer
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
You don't need to use cat if you do
xargs -a filelist.txt -n 1 -I {} echo mv {} your/new/path/{}
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: Executeutilityfor each input line
-n number: Set the maximum number of arguments taken from standard input for each invocation ofutility.
Log in to answer this question.
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
forloop and then simplymv that_file /home/venkat/Gemmatimonadota/HQ. I will leave you to find the specific answer.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
You appear to be missing back-ticks around the
catcommand. Try the command above. If all command lines (that will be simply printed to screen) look right, then remove the wordechoto 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.
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.