From J Wiki
Jump to navigation Jump to search
User Guide Installation Development Categories Git Build Log

tables/dsv - Delimiter-Separated-Value utilities

  • Provides verbs to read from and write to delimiter-separated-value (DSV) files or strings,
  • supports appending arrays to an existing dsv file,
  • optional user-defined field delimiter (default is TAB)
  • optional user-defined string delimiter(s) (default is ")
  • ability to convert fields to numeric type where possible

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


Use JAL/Package Manager.

Load dsv addon with the following line

   load 'tables/dsv'

Examples of use

    • only literal cells of J array are enclosed by string delimiters
   ]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 β”‚
   1+ makenum fixdsv tstarry
1  2  3  4
5  6  7  8
9 10 11 12
 * writedsv and makedsv can handle boxed arrays with cells containing numeric

arrays, boxed or complex data

   ]tstarry=: ((34j3;2;<<4),:2;3 6;3)
β”‚34j3β”‚2  β”‚β”Œβ”€β”β”‚
β”‚    β”‚   β”‚β”‚4β”‚β”‚
β”‚    β”‚   β”‚β””β”€β”˜β”‚
β”‚2   β”‚3 6β”‚3  β”‚

   load 'tables/dsv'
   ';' makedsv tstarry
2;3 6;3
 * fixdsv unescapes quotes embedded in fields
   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.


Contributed by Ric Sherlock

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

See Also

  • csv addon - Utilities for working with comma-separated-value (CSV) files.
  • csvedit addon - GUI application for creating and editing CSV files.