Extending....
dat=. 'b' fread 'temp/t1.txt' dat=. cut each dat len=. >./ # &> dat len $ &> dat NB. reshape to required shape
There happen to be 'empty' rows in the input file. If the input file is clean, this works. Else, the reshape line (marked with NB.) fails!! So, how should I "clean" the input file before reading it? Here I want to remove the empty lines and have only the lines that have data to be used. On 10/6/06, Chris Burke <[EMAIL PROTECTED]> wrote:
Yuvaraj Athur Raghuvir wrote: > 1) Input file: > aaa bb cccc dd e > 1111 22 33333 444 55555 6 7 8 > > 2) Read input as an array of values. > > data =: cut"1 'm' freads y NB. y is the fully qualified file name > > data > +----+--+-----+---+-----+-+-+-+ > |aaa |bb|cccc |dd |e | | | | > +----+--+-----+---+-----+-+-+-+ > |1111|22|33333|444|55555|6|7|8| > +----+--+-----+---+-----+-+-+-+ > > 3) Now, pad the matrix in a way similar to $ operator for each dimention. > So, end result should look like: > +----+--+-----+---+-----+----+----+-----+ > |aaa |bb|cccc |dd |e | aaa| bb |cccc | > +----+--+-----+---+-----+----+----+-----+ > |1111|22|33333|444|55555|6 |7 |8 | > +----+--+-----+---+-----+----+----+-----+ The expression cut"1 'm' freads y pads out the first row with empties so that it matches the length of the second row. Better not to pad at all, but use reshape: dat=. 'b' fread 'temp/t1.txt' dat=. cut each dat len=. >./ # &> dat len $ &> dat +----+--+-----+---+-----+---+--+----+ |aaa |bb|cccc |dd |e |aaa|bb|cccc| +----+--+-----+---+-----+---+--+----+ |1111|22|33333|444|55555|6 |7 |8 | +----+--+-----+---+-----+---+--+----+ ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
