A common requirement when using CSVfix is to apply a command to only some records in the CSV input data. To a certain extent you can manage this using commands like find to filter the input, and operating system pipes to connect the filtered input to the relevant command. However, this isn't always what is wanted, and so from version 1.5 of CSVfix, the ability to filter input for most commands has been added using the -skip and -pass options.


The -skip option  is probably the easier of the two options to understand. Suppose you want to re-order the names.csv data, so that surnames come first, but only for female authors. You can use the -skip option to do this, together with the  order command (please see here for information on the quoting required by the expression language):


csvfix order -skip "$3 != 'F'" -f 2,1 names.csv


The parameter  "$3 != 'F'" of the -skip option is an expression in the CSVfix expression language, which will be evaluated for every CSV input record. If the expression evaluates to true, then the input record is discarded, is not fed into the actual command (order, in this case), and so produces no output. The result of this command is:


"Austen","Jane"

"Elliot","George"

"Woolf","Virginia"


The -pass option works somewhat similarly. Suppose that instead of discarding the male authors, you want them in the output, but you do not want them re-ordered:


csvfix order -pass "$3 != 'F'" -f 2,1 names.csv


In this case, if the expression specified by -pass evaluates to true, the CSV input record is passed to the output unchanged, so the result of this command is:


"Charles","Dickens","M"

"Austen","Jane"

"Herman","Melville","M"

"Flann","O'Brien","M"

"Elliot","George"

"Woolf","Virginia"

"Oscar","Wilde","M"


The -skip and -pass options are currently implemented for the following commands (asterisk indicates -skip only):


ascii_table *

 call

date_format

date_iso

echo *

edit

escape

eval

exclude

exec

file_info

file_split

flatten *

merge

money

order

pad

printf

rmnew

sequence

split_char

split_fixed

sql_delete *

sql_insert *

sql_update

template *

timestamp

to_xml *

trim

truncate

unflatten *

validate *

write_dsv *

write_fixed *

head *

tail *


Created with the Personal Edition of HelpNDoc: Easy CHM and documentation editor