1

I've been trying to run a while-loop in parallel for a work that takes days.

I've seen other answers where parallel was implemented within a while-loop, but for that case it does work in blocks, where the next job only works after all previous jobs finished.

This is the code, which reproduced the two columns of the CSV file:

while IFS="," read fq tab
do
echo $fq
echo $tab
done < /home/samples.csv

where the csv file contain two columns with no header (column 1 and 2), where the variables are stored. For example:

a1,b1
a2,b2
a3,b3
a4,b4

I've been trying to run this in parallel so when a job is finished the other starts immediately because of the long run times.

This is the code:

while IFS="," read fq tab
do
parallel -j 1 --verbose --delay 2  "echo $fq; echo $tab" 
done < /home/samples.csv

But this produces

a1 b1 a1,b1

a1 b1 a2,b2

a1 b1 a3,b3

a1 b1 a4,b4

And not

a1   b1
a2   b2
a3   b3
a4   b4
7
  • 3
    if you need the results of processing a1 b1 for processing a2 b2 then you can't parallelize the code Commented Jan 26, 2022 at 20:13
  • 3
    To get your expected result: with parallel: parallel -j 3 -a /home/sample.csv --colsep ',' echo {1} {2}. Knowing if this will suit your final goal is an other story. Commented Jan 26, 2022 at 20:21
  • I don't need the results of a1 and b1 to proceed! They are independent in this case Commented Jan 26, 2022 at 20:28
  • 1
    I'm unable to reproduce your ouput (wrong or expected); 'course, it doesn't help that you're trying to parse input lines with IFS="," but there are no commas in the input file; consider reviewing How to create a minimal, reproducible example? and then come back and update your question accordingly, making sure your expected output matches the sample input you provide Commented Jan 26, 2022 at 20:30
  • 1
    The answer from Zeitounator should be all you need. Commented Jan 26, 2022 at 22:38

1 Answer 1

4
cat <<_EOF > samples.csv
a2,b2
a3,b3
a4,b4
_EOF

cat samples.csv | parallel --colsep , echo column 1 = {1} column 2 = {2}

If samples.csv is TAB separated, ; separated, or separated with spaces:

cat samples.csv | parallel --colsep '\t' echo column 1 = {1} column 2 = {2}
cat samples.csv | parallel --colsep ';' echo column 1 = {1} column 2 = {2}
cat samples.csv | parallel --colsep ' +' echo column 1 = {1} column 2 = {2}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.