tables/dsv - Delimiter-Separated-Value utilities

The tables/dsv addon can be used for comma-separated-value files (CSV) files, but the tables/csv addon handles that format specifically.

Browse history, source and examples in SVN.

Verbs available

appenddsv

v

Appends an array to a dsv file

enclose

v

Encloses string in quotes

fixdsv

v

Convert dsv data into J array

makedsv

v

Makes a DSV string from an array

makenum

v

Converts cells in array of boxed literals to numeric where possible

makenumcol

v

Converts columns of boxed literals to numeric if possible for all cells in a column

readdsv

v

Reads dsv file into a boxed array

writedsv

v

Writes an array to a dsv file

Installation

Use JAL/Package Manager.

Load dsv addon with the following line

   load 'tables/dsv'

Examples of use

   ]tstarry=: ('Hello';44.3;'to you';56),:'to me';39.22;'Bye now';'72'
┌─────┬─────┬───────┬──┐
│Hello│44.3 │to you │56│
├─────┼─────┼───────┼──┤
│to me│39.22│Bye now│72│
└─────┴─────┴───────┴──┘
   makedsv tstarry
"Hello" 44.3    "to you"        56
"to me" 39.22   "Bye now"       "72"

   (',';'{}') makedsv tstarry
{Hello},44.3,{to you},56
{to me},39.22,{Bye now},{72}

makenum and makenumcol can be used to convert cells that are string representations of numbers to numeric.

   ]tstarry=: makedsv 8!:0 i. 3 4
"0"     "1"     "2"     "3"
"4"     "5"     "6"     "7"
"8"     "9"     "10"    "11"

   fixdsv tstarry
┌─┬─┬──┬──┐
│0│1│2 │3 │
├─┼─┼──┼──┤
│4│5│6 │7 │
├─┼─┼──┼──┤
│8│9│10│11│
└─┴─┴──┴──┘
   1+ makenum fixdsv tstarry
1  2  3  4
5  6  7  8
9 10 11 12

   ]tstarry=: ((34j3;2;<<4),:2;3 6;3)
┌────┬───┬───┐
│34j3│2  │┌─┐│
│    │   ││4││
│    │   │└─┘│
├────┼───┼───┤
│2   │3 6│3  │
└────┴───┴───┘

   load 'tables/dsv'
   ';' makedsv tstarry
34j3;2;4
2;3 6;3

   tstdsv=: '"Symbol "" is Rank"|38|"abc"',LF,'"Hello world"|56|"efg"',LF
   ('|';'""') fixdsv tstdsv
┌────────────────┬──┬───┐
│Symbol " is Rank│38│abc│
├────────────────┼──┼───┤
│Hello world     │56│efg│
└────────────────┴──┴───┘

To see more examples of usage, open and inspect the test_dsv.ijs script.

Authors

Contributed by RicSherlock

Suggestions and/or SVN improvements to the addon are welcome.

See Also

Addons/tables/dsv (last edited 2010-05-31 05:17:57 by RicSherlock)