Skip to main content

## exec

The exec command is used to execute an external command, using the CSV input data as command parameters. This command is intended to be used when the built-in features of CSVfix do not suffice to solve a problem.

See also: eval, call

Flag | Req'd? | Description
-c cmd | Yes | Specifies the command to be executed together with the parameters to use. Parameters are specified by place-holders in the format %1, %2 etc. which indicate the first, second (and so on) CSV fields. The command is executed once for each CSV input record. For example: -c "echo %1 %4" specifies that the echo command should be called for each CSV input record, with the values in CSV input fields 1 and 4 as parameters. If you need a literal % character in the command, use a %% pair.
-r | No | By default, the command's output is parsed as CSV and the resulting column(s) are appended to the input row. Using the -r flag causes the command's output to replace all the input record data and to be treated as plain text
-ix ecode | No | Tells the command to ignore exit codes from the command being executed which have values less than or equal to ecode. This is useful for commands like grep which return non-zero values even though the command has worked. For example: csvfix exec -ix 1 -c 'grep %1 data/books.csv' data/names.csv If the -ix option were not used you would get a "Command execution error" message if the grep for a name failed.

The following example transliterates all lower-case vowels in the surname & forename fields of names.csv into an upper-case X character by using the UN*X tr command:

csvfix exec -c 'echo %1 %2 | tr aeiou X' data/names.csv

which produces:

"Charles","Dickens","M","ChXrlXs DXckXns"

"Jane","Austen","F","JXnX AXstXn"

"Herman","Melville","M","HXrmXn MXlvXllX"

"Flann","O'Brien","M","FlXnn O'BrXXn"

"George","Elliot","F","GXXrgX EllXXt"

"Virginia","Woolf","F","VXrgXnXX WXXlf"

"Oscar","Wilde","M","OscXr WXldX"

Created with the Personal Edition of HelpNDoc: Single source CHM, PDF, DOC and HTML Help creation

####