All Projects → archiecobbs → csvprintf

archiecobbs / csvprintf

Licence: Apache-2.0 License
Simple CSV file parser for the UNIX command line

Programming Languages

c
50402 projects - #5 most used programming language
Roff
2310 projects
shell
77523 projects
M4
1887 projects
XSLT
1337 projects
Makefile
30231 projects
Scilab
70 projects

csvprintf is a simple UNIX command line utility for parsing CSV files.

cvsprintf works just like the printf(1) command line utility. You supply a printf(1) format string on the command line and each record in the CSV file is formatted accordingly. Each format specifier in the format string contains a column accessor to specify which CSV column to use, so for example %3$d would format the third column as a decimal value.

csvprintf can also convert CSV files into XML and JSON documents.

You can view the ManPage online.

Examples

Given this input file input.csv:

NAME,ADDRESS,POINTS
Fred Smith,"1234 Main St.
Anytown, USA   39103",123.4567
"Wayne ""The Great One"" Gretsky",  59 Hockey Lane  , 999999

here is the resulting output:

$ cat input.csv | csvprintf -i 'Name:    [%1$-24.24s]\nAddress: [%2$-12.12s]\nPoints:  %3$.2f\n'
Name:    [Fred Smith              ]
Address: [1234 Main St]
Points:  123.46
Name:    [Wayne "The Great One" Gr]
Address: [59 Hockey La]
Points:  999999.00

An example of the XML output:

$ cat input.csv | csvprintf -iX
<?xml version="1.0" encoding="ISO-8859-1"?>
<csv>
  <row>
    <NAME>Fred Smith</NAME>
    <ADDRESS>1234 Main St.
Anytown, USA   39103</ADDRESS>
    <POINTS>123.4567</POINTS>
  </row>
  <row>
    <NAME>Wayne "The Great One" Gretsky</NAME>
    <ADDRESS>59 Hockey Lane</ADDRESS>
    <POINTS>999999</POINTS>
  </row>
</csv>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].