GNU parallel colsep with missing columns

主宰稳场 提交于 2019-12-11 05:32:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!