Such things are why I still use my simplistic file covers rather than library ones ... but a thing to watch out for in Henry's terse example -

  <;._2@(,&TAB) ;._2 (1!:1) filename

is that Excel doesn't end the last line of saved files with a newline, maybe you are aware of that because the example file was very explicit about including that last $ ... Why Excel doesn't do this is one of the mysteries of MS...

When I'm dealing with such files, I always filter them so that every "field" ends with a TAB and every line (including the last) with a LF. Then the direct expression is even more compact -

  <;._2;._2 (1!:1) <'filename'

(note that Henry's expression assumes "filename" is boxed.)


At 20:11  +0300 2008/06/28, Lippu Esa wrote:
Thank you! Just the information I needed!

Esa
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Henry Rich
Sent: 28.06.2008 20:00
To: 'Programming forum'
Subject: RE: [Jprogramming] Problem with the last column of a tab
delimetedfile

The problem is that
'm' freads
is returning a table.  This table must have lines of the same length,
so the short ones are being padded with spaces.

You need to use
'b' freads
which will box the lines so that they can have different lengths.

Or, you can just do 1!:1 to read your file, something like
<;._2@(,&TAB) ;._2 (1!:1) filename

Henry Rich


 -----Original Message-----
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Lippu Esa
 Sent: Saturday, June 28, 2008 9:22 AM
 To: Programming forum
 Subject: [Jprogramming] Problem with the last column of a tab
 delimeted file

 Hi!

 I'm trying to read a tab delimited file from Excel.

 It contains empty columns at the end of the lines (except the header
 line).

 However, the last empty column contains blanks that I must trim away.

 No big deal but I'd like to know how to read the file "by the book".

 I read the file like this:

    tab=.9 { a.
tbl=: <;._2 "1 (,.&tab 'm' freads 'test.txt') ]hdr=.{.tbl
 +--+-+--+--+
 |id|c|a1|a2|
 +--+-+--+--+
]dat=.}.tbl
 +-+-++-----+
 |1|a||     |
 +-+-++-----+
 |2|b||     |
 +-+-++-----+
 |3|c||     |
 +-+-++-----+

 This is the file test.txt (^I=tab, $=LF):

 id^Ic^Ia1^Ia2$
 1^Ia^I^I$
 2^Ib^I^I$
 3^Ic^I^I$

 The J version is 6.01c (j 6.02a downloaded, not yet installed)

 Any suggestions?

 Esa

 ----------------------------------------------------------------------
 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

Reply via email to