Addons/tables/dsv
< Addons
Jump to navigation
Jump to search
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
Installation
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 β βββΌββΌβββΌβββ€ β8β9β10β11β βββ΄ββ΄βββ΄βββ 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 34j3;2;4 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.
Authors
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.