To write rows without trailing blanks (on linux, so separator is LF):

   (;rows ,each LF) fwrites 'testfile'
19

Also, following your example, define A as a character matrix:

   $A=: ,"2 > rows
4 5

This has rows padded with trailing blanks:

   (,A,.LF) fwrites 'testfile'
24

Use dltbs to remove the trailing blanks before writing:

   (dltbs ,A,.LF) fwrites 'testfile'
19

On Mon, Mar 18, 2019 at 6:26 AM Lippu Esa <[email protected]> wrote:

> Hello,
>
> I need to write out a text file with variable length lines and no trailing
> spaces. I can do it externally with sed but I'd prefer do it the J way.
>
> However, I can't figure it out. Any help would be greatly appreciated.
>
> Esa
>
>    require '~addons/general/misc/format.ijs'
>    1!: 44 'c:/temp'
>
>    ]rows=:4 1 $;:'one two three four' NB. the real file is a .csv from
> Excel
> +-----+
> |one  |
> +-----+
> |two  |
> +-----+
> |three|
> +-----+
> |four |
> +-----+
>
>    (,"2>rows) fwrites 'testfile'
> 28
>
>    NB. test file has unwanted trailing spaces
>    hexdump shell 'type testfile'
> 00  6F 6E 65 20-20 0D 0A 74  77 6F 20 20-0D 0A 74 68  |one  ..two  ..th|
> 10  72 65 65 0D-0A 66 6F 75  72 20 0D 0A              |ree..four ..    |
>
>    NB. desired result
>    hexdump shell 'sed ''s/  *$//'' testfile'
> 00  6F 6E 65 0D-0A 74 77 6F  0D 0A 74 68-72 65 65 0D  |one..two..three.|
> 10  0A 66 6F 75-72 0D 0A                              |.four..         |
>
> ---
> ----------------------------------------------------------------------
> 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