Wednesday, October 27, 2021

[SOLVED] How to insert sleep in GNU parallel?

Issue

I am trying to execute this command below. I have a list of 100 samples in 100_samples_list.txt. I want to use each sample as input and execute the command and output to OUTPUT.csv. However, in due process I also want to execute sleep for 2 seconds. How do I do here with this code?

parallel -j3 \
"IFS=$'\n';"'for hit in \
$(esearch -db sra -query {} | efetch --format runinfo | grep SRR); do \
echo "{},${hit}"; done' \
:::: "100_samples_list.txt" \
| sort -t, -k9,9rn >> OUTPUT.csv

I tried to insert sleep 2 in first line of above code, but it won't work parallel -j3 sleep 2 \


Solution

I assume you want to wait 2 seconds before starting a new job:

doit() {
  sample="$1"
  IFS=$'\n'
  for hit in $(esearch -db sra -query "$sample" | efetch --format runinfo | grep SRR); do
    echo "$sample,${hit}";
  done
}
export -f doit
parallel --delay 2 -j3 doit :::: "100_samples_list.txt" | sort -t, -k9,9rn >> OUTPUT.csv


Answered By - Ole Tange