问题
I have a program that takes a variable number of arguments and I want to run the program in parallel with one instance for each line of an input file. The input file is comma separated with some missing columns at the end of some rows. How can I instruct GNU parallel to skip the parameter substitution when the column is missing?
Input File
A,B,C,D,E
A,B,C,D
A,B,C
Script
parallel -a $1 --trim lr --colsep ',' echo {1} {2} {3} {4} {5}
Output
A B C D E
A B C D {5}
A B C {4} {5}
Desired Output
A B C D E
A B C D
A B C
回答1:
parallel -a $1 --trim lr --colsep ',' echo {}
回答2:
If you just want to replace commas for another char (like space), simply:
cat YOUR_FILE | parallel --pipe sed \'s/,/ /g\'
Wher the " " between the "," and "g" is the character that will replace your comma.
If you also want to do some transformations managing columns, try awk
.
来源:https://stackoverflow.com/questions/38790690/gnu-parallel-colsep-with-missing-columns