-1

I have a file, abc.txt, like this on a Linux machine:

abc|yes|50c|1|pending
bcd|no|100c|1|pending
cde|yes|45c|2|pending
def|no|44c|2|pending

I have split this file into two files based on the 4th field. 1.txt:

abc|yes|50c|1|pending
bcd|no|100c|1|pending

And 2.txt

cde|yes|45c|2|pending
def|no|44c|2|pending

If the second field is 'yes' I want to call a script with the 3rd field as a parameter, or if the second field is 'no' the 1st field as a parameter, and run the scripts in parallel. 1.txt should run, then 2.txt and if any script fails it should update the last field from pending to FAILED/SUCCESS.(my scripts passes 0-success,1-failed return code)

For example:

1.txt

ksh script1.ksh 50c
ksh script1.ksh bcd

2.txt

ksh script1.ksh 45c
ksh script1.ksh def
1
  • Please use the formatting tools to format your post. You can use code blocks for your file data. Also, please show us what you have so far so we don't need to reinvent what you have already solved. – terdon Aug 10 '20 at 13:52
0
#!/bin/bash

runksh() {
    ksh script1.sh "$1";
}
export -f runksh

doit() {
    parallel --joblog +my.log --colsep '\|' \
             runksh '{=1 $_ = $arg[2] eq "yes" ? $arg[3] : $arg[1] =}' {};
}
export -f doit

parallel -u --colsep '\|' -j1 --group-by 3 --pipepart -a abc.txt doit

# my.log now contains whether a job succeeded or failed
# Extract exit code + argument
awk -e '$7 != 0 { print $11"|"$12"|"$13"|"$14"|FAILED"; }' my.log > failed
awk -e '$7 == 0 { print $11"|"$12"|"$13"|"$14"|SUCCEEDED"; }' my.log > succeeded
cat failed succeeded
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.