This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I save terminal output to a folder

Hi am going to run prodigal using multiple files. So I want to save each results in different folder. How to save prodigal output into folder?

alignment

Hello akhilvbioinfo!

We believe that this post does not fit the main topic of this site.

I think this is a typical shell question where the answer doesn't depend on what type of program it is, try to search for "redirect shell output". Also, you might need to check out more shell tools to capture the whole output: see man bash section on Pipelines, commands tee, nohup etc.

e.g. the answer is here: http://stackoverflow.com/questions/6674327/redirect-all-output-to-file

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

3 answers

Hi,

Each time you want to save an output from terminal to a file you can use the symbol > at the end of the command, with the name of your file.

​my_command > my_file

Or if you want to append content:

​my_command >> my_file

In MacOs for example, you can save the terminal content in a file with "command + S".

I do not know if it's exactly what you want, but if you run on multiples files, you just have to use a variable and change the file name automatically.

A simple loop to deal with all files than end with *.fasta in a dir:

for f in *.fasta; 
do 
NAME=$(basename "$f" .fasta); 
mkdir $NAME; 
prodigal -i $f -a $NAME/$NAME.faa -d $NAME/$NAME.ffn -o $NAME/$NAME.gff -f gff; 
done

You can delete the linebreaks and run the command as such.

A routine to run the same command/program for all the files of your current directory, generating a new folder and storing the results in it could be:

    for fil in `ls *.your_extension`;
    do
      filetag=`echo "$fil" | cut -d'.' -f1`;
      mkdir $filetag;
      your_program $fil > ./$filetag/output.your_extension;
    done

With this you read all the files with your selected extension in the working directory, generate a new folder there containing a base name generated from the original file name but without the extension and run your command/program storing the output to a file placed in it.

Log in to answer this question.