IntroductionThat's a grep-like program that handles csv files (or even any delimited file format) by filtering its columns' content through a extremely simple syntax. Usage
Usage: csvgrep [options] [expression] file
Options:
--show-header print enumerated column titles
(this option must be used alone and without expression)
--with-header print the column titles in the first output line
--no-quote print fields unquoted, even if needs to be quoted
(eg. comma separated fields into csv files)
--close print a separator at the last position of each output line
--print-all send to output: (i) all input fields or
(ii) all not hidden fields (when some column is hidden)
--separator=S set S as input and output separator (',' is the default separator)
--output-separator=S set S as output separator (is overriden when --separator is used)
--input-separator=S set S as input separator (is overriden when --separator is used)
--help print this message
Expression syntaxExpression is a comma separated list with key only or key-value pairs. The key-value structure has the general syntax: [[] [!] KEY[=VALUE] []] where:
The columns' ids are obtained with the command: $ csvgrep --show-header names.csv 0,First Name 1,Middle Name 2,Last Name 3,Job Title 4,Salary The numbers at the beginning of each line are the columns' ids. ExamplesPrint all fields for each line where the column titled "Middle Name" matches the regular expression Doe$. If the "Middle Name" column doesn't exist an error is raised. $ csvgrep --print-all "Middle Name=Doe$" names.csv Print "First Name" and "Salary" columns and hides "Middle Name" column. $ csvgrep "[Middle Name=Doe$], First Name, Salary" names.csv Print all lines that don't match the regular expression. $ csvgrep "[! Middle Name=Doe$], First Name, Salary" names.csv Print the first and third column $ csvgrep "0, 3" any.csv Print the first and third column and filters by the fourth $ csvgrep "0, 3, [4=True]" any.csv Emulating unix commands
Tips
ProjectThe project is hosted at Google: Download
Last modified December 6, 2008 9:29 pm / Skin by Kevin Hughes
![]() |