0

I have a script like this:

#!/bin/csh

command 1 \
   -f \"input1\" \
   -l input2 -other_swithes1

command 2 \
   -f \"input1\" \
   -m input2 \
   -l input3 -other_swithes1

command 3 \
   -f \"input1\" \
   -l input2 -other_swithes2

so any idea for an one-liner with xargs to run these commands in parallel. I tried various variants but all failed. I do not really want to write a script, I think that should have been possible with -d switch and -c, not sure though.

To simplify and extend the problem further, what I have is

cat file | grep -v "#.*" | sed -z 's/[\]\n/ /g' | xargs -I {} -n1 -P10 sh -c '{}'

and while this does the job there is a particular problem and that is that \" get removed. So any clue how to solve that?!

10
  • could probably do something with xargs -n, but might need an intermediate scriptlet to put the input arguments in the right places wrt. the options. Also the fact that seem to have one command with three args, and the other two with only two args is an annoyance. Makes the intermediate script more complex.
    – ilkkachu
    Aug 23, 2021 at 12:38
  • 5
    But you already have a script. Why don't you just add & to the end of each of the three commands in your script? That will run them in parallel.
    – terdon
    Aug 23, 2021 at 12:44
  • @terdon because, when I am running the script, I do not want to run them in parallel, further I can pip prior to xargs and filter out some that I do not run all of them in parallel.
    – inman
    Aug 23, 2021 at 12:58
  • 2
    Please edit your question and explain all this. We need to know the context in order to help you. You're probably looking for GNU parallel though, not xargs.
    – terdon
    Aug 23, 2021 at 13:08
  • 3
    "I do not really want to write a script" huh? You've already written one Aug 23, 2021 at 13:35

2 Answers 2

1

With GNU Parallel you can do something like:

parallel -d '\n\n' < file.csh

Disclosure: I am the author of this tool.

-1

So the answer is:

cat file | grep -v "#.*" | sed -z 's/[\]\n/ /g' | sed -z 's/\"/\\\\"/g' | xargs -I {} -n1 -P10 sh -c '{}'

Thanks

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .