I use a verb called (readtd2) for this: The tacit defn is (all that follows
is one line which
email typically mangles):
NB. read TAB delimited table files - faster than (readtd) - see long
document
readtd2=:[: <;._2&> (9{a.) ,&.>~ [: <;._2 [: (] , ((10{a.)"_ = {:) }.
(10{a.)"_) (13{a.) -.~ 1!:1&(]`<@.(32&>@(3!:0)))
This defn is explained by the "long document" pulled straight out of my JOD
utils dictionary.
*readtd2 v-- read and parse TAB delimited table files.
This verb is somewhat faster and can be considerably more
space efficient than (readtd). It also corrects the expansion
of the last column.
verbatim:
NB. explicit definition
readtd2=: (13 : '<;._2&> (<;._2 tlf (read y) -. CR) ,&.> TAB') f.
NB. timing tests with (readtd)
f=. 'c:\temp\smugimagetable.txt'
NB. to even out I/O bias run the timings in random order
s=. ;50 # <'readtd2 f';'readtd f'
p=. ?~ #s
NB. apply random permutation, time and invert permutation
t=. (/:p){tms&> p{s
NB. even=readtd2, odd=readtd
mean=. +/ % #
mean"1 |: (-.2 | i. #t)#t
mean"1 |: (2 | i. #t)#t
The verbs (tlf) and (read) are respectively:
NB. appends trailing line feed character if necessary
tlf=:] , ((10{a.)"_ = {:) }. (10{a.)"_
NB. reads a file as a list of bytes
read=:1!:1&(]`<@.(32&>@(3!:0)))
On Fri, Mar 4, 2016 at 1:51 AM, Skip Cave <[email protected]> wrote:
> Ric,
>
> Nice! I was looking for csv utilities on the main Jsoftware.com site.
> It turns out that the good doc is on the code.jsoftware.com site.
>
> The "assign2hdr" verb is very handy. Thanks for pointing it out!
>
> Skip
>
>
>
> On Thu, Mar 3, 2016 at 6:21 PM, Ric Sherlock <[email protected]> wrote:
> > Note also:
> >
> > assign2hdr readcsv 'c:\tst1.csv'
> >
> > col1
> >
> > +---+---+----+
> >
> > |abc|def|ghij|
> >
> > +---+---+----+
> >
> > col2
> >
> > +----+----+----+
> >
> > |c101|c102|c201|
> >
> > +----+----+----+
> >
> > col3
> >
> > 1 1 2
> >
> >
> >
> > On Fri, Mar 4, 2016 at 1:04 PM, Ric Sherlock <[email protected]> wrote:
> >
> >> Many of the addons have documentation on the wiki:
> >> Note that the 'tables/csv' addon
> >> http://code.jsoftware.com/wiki/Addons/tables/csv
> >>
> >> is a special case of the 'tables/dsv' addon which lets you specify
> custom
> >> delimiters.
> >> http://code.jsoftware.com/wiki/Addons/tables/dsv
> >>
> >> On Fri, Mar 4, 2016 at 12:16 PM, Raul Miller <[email protected]>
> >> wrote:
> >>
> >>> It could probably use better documentation.
> >>>
> >>> For now... there's a brief reference left over from j602:
> >>> http://www.jsoftware.com/docs/help602/user/script_csv.htm
> >>>
> >>> Also, there's the NB. comments that you can read if you run:
> >>> open 'csv'
> >>>
> >>> Note also that this probably requires that you have installed the
> >>> tables/csv addon. (Though, personally, I always just do (install'all')
> >>> in jconsole in any fresh J installation.)
> >>>
> >>> Thanks,
> >>>
> >>> --
> >>> Raul
> >>>
> >>>
> >>> On Thu, Mar 3, 2016 at 6:06 PM, Skip Cave <[email protected]>
> >>> wrote:
> >>> > Thanks Raul, that worked perfectly!
> >>> > Where is that command documented? I looked for awhile, but couldn't
> find
> >>> > any clear docs.
> >>> >
> >>> >
> >>> > On Thu, Mar 3, 2016 at 4:25 PM, Raul Miller <[email protected]>
> >>> wrote:
> >>> >
> >>> >> Unless it's huge, I think I'd go:
> >>> >>
> >>> >> require'csv'
> >>> >> list=: readcsv 'c:\tst1.csv'
> >>> >>
> >>> >> Thanks,
> >>> >>
> >>> >> --
> >>> >> Raul
> >>> >>
> >>> >>
> >>> >> On Thu, Mar 3, 2016 at 5:20 PM, Skip Cave <[email protected]>
> >>> wrote:
> >>> >> > I have a text file that looks like this:
> >>> >> >
> >>> >> > col1,col2,col3
> >>> >> > abc,c101,1
> >>> >> > def,c102,1
> >>> >> > ghij,c201,2
> >>> >> >
> >>> >> > the file name is "tst1.csv"
> >>> >> >
> >>> >> > The location of the file is C:\tst1.csv
> >>> >> >
> >>> >> > i want to read the file into a boxed J array
> >>> >> > called "list"
> >>> >> >
> >>> >> > list
> >>> >> >
> >>> >> > ┌────┬────┬────┐
> >>> >> > │col1│col2│col3│
> >>> >> > ├────┼────┼────┤
> >>> >> > │abc │c101│
> >>> >> >
> >>> >> > 1
> >>> >> >
> >>> >> > │
> >>> >> > ├────┼────┼────
> >>> >> >
> >>> >> > ┤
> >>> >> > │def │c102│
> >>> >> >
> >>> >> > 1
> >>> >> >
> >>> >> > │
> >>> >> > ├────┼────┼────┤
> >>> >> > │ghij│c201│
> >>> >> >
> >>> >> > 2
> >>> >> >
> >>> >> > │
> >>> >> > └────┴────┴────┘
> >>> >> >
> >>> >> > What utilities have
> >>> >> > t
> >>> >> > o be loaded
> >>> >> > to do this?
> >>> >> > What are the load commands?
> >>> >> > What is the file-read, path, and assignment command(s) required
> to do
> >>> >> this?
> >>> >> >
> >>> >> > Skip
> >>> >> >
> >>> >> > Skip Cave
> >>> >> > Cave Consulting LLC
> >>> >> >
> >>> ----------------------------------------------------------------------
> >>> >> > For information about J forums see
> >>> http://www.jsoftware.com/forums.htm
> >>> >>
> ----------------------------------------------------------------------
> >>> >> For information about J forums see
> http://www.jsoftware.com/forums.htm
> >>> >
> ----------------------------------------------------------------------
> >>> > For information about J forums see
> http://www.jsoftware.com/forums.htm
> >>> ----------------------------------------------------------------------
> >>> For information about J forums see http://www.jsoftware.com/forums.htm
> >>>
> >>
> >>
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
John D. Baker
[email protected]
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm