sortandprint=:4 : 0

text=.'b' fread y

text=./:~text

text=.text,&.>LF

(;text) fwrite x

)


The 'b' option means box each line.


y is file to read,

x is file to write sorted.


If you are dealing with windows and need CRLF as a line separator, replace
the LF with <CRLF.


On Sun, May 26, 2013 at 1:50 PM, Murray Eisenberg <[email protected]>wrote:

> I'm really out of practice with J, and the meager-to-nonexistent
> documentation is not helping me. I have a very simple task to perform. I
> have a text file infile.txt on my desktop and here's what I want to do:
>
>  (1) read the file as lines (so I don't get all the end-of-line symbols);
>  (2) sort the file's lines (alphabetically)
>  (3) write out the result as a new text file, say outfile.txt, also on my
> desktop.
>
> I can do this trivially in Mathematica:
>
>  t = Import["~/Desktop/infile.txt", "Lines"]
>  Export["~/Desktop/outfile.txt", Sort[t]]
>
> But how would I do this in J (which, for longer files, ought to be faster)
> and how would I discover how to do it? I prefer to use named library
> functions where applicable.
>
> I tried the following in J801, after looking into text.ijs from J602:
>
>   load 'files'
>   t=. fread '~/Desktop/infile.txt
>   load 'text'
>   cuttext t
> | value error: cuttext
>
> What happened there?
>
> [Hope this is not too basic for this forum (as compared with
> [email protected]).]
>
> ---
> Murray Eisenberg                                    [email protected]
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower            phone 413 549-1020 (H)
> University of Massachusetts                               413 545-2838 (W)
> 710 North Pleasant Street                         fax   413 545-1801
> Amherst, MA 01003-9305
>
>
>
>
>
> ----------------------------------------------------------------------
> 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