Steve
Steve

Reputation: 1292

GNU parallel colsep with missing columns

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

Upvotes: 2

Views: 1414

Answers (2)

Ole Tange
Ole Tange

Reputation: 33740

parallel -a $1 --trim lr --colsep ',' echo {}

Upvotes: 3

arutaku
arutaku

Reputation: 6107

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.

Upvotes: 0

Related Questions