How to run multiple commands on Mac OSX
1
0
Entering edit mode
7.3 years ago
hexphe ▴ 10

Hello,

I need to run a command for each of my 50 samples. My 50 commands look like as follows:

obiconvert --uppercase Sample1.fastq > Sample1_edit.fastq

.........

obiconvert --uppercase Sample50.fastq > Sample50_edit.fastq

Each command would take ~2 minutes. I do not want to copy and past 50 times. I copied all of the 50 commands and pasted all of them in the Mac terminal. After running, I found the size of output files for a few samples are zero bytes: the commands for those samples did not run properly. I re-run the commands for those samples one by one, and the output files are normal.

How to run multiple commands on Mac OSX? Is there a easy way to run the 50 commands?

Thanks!

next-gen • 3.8k views
ADD COMMENT
1
Entering edit mode

the macOS (OS X) terminal uses the bash shell by default. As such, you can take advantage of shell scripting for these kinds of tasks. There are plenty of tutorials on how to do this, check out some of these. If you need ideas on how to set up scripts, you can look for examples on the internet.

ADD REPLY
0
Entering edit mode

Thank you for the links.

ADD REPLY
3
Entering edit mode
7.3 years ago
GenoMax 147k

You would use a bash script for this. Something like:

for i in `ls -1 *.fastq | sed 's/.fastq//'`; do obiconvert --uppercase $i.fastq > $i\_edit.fastq; done
ADD COMMENT
0
Entering edit mode

Thank you very much for the script. It works well.

ADD REPLY

Login before adding your answer.

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