Great!

Many thanks for your solutions, David and Chris!

Esa

-----Original Message-----
From: Programming <[email protected]> On Behalf Of David 
Mitchell
Sent: Monday, March 18, 2019 3:50 PM
To: [email protected]
Subject: Re: [Jprogramming] How to write a text file without trailing blanks

Hi Esa,

This is a quick and dirty way:

;(],&LF)&.> 'Test';'ing';'elephant'

Cheers,
David

On 3/18/2019 09:26, Lippu Esa 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 
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&amp;data=01%7C01%7C%7C784a37dd8fa340cc2fe708d6aba8a4ee%7C5090e269dbea4e98a9aa3e70be5890f7%7C0&amp;sdata=ij4WseYGXKkK4qh1SBIsc9fL3ZvA5JMMUrDoQfvQOlg%3D&amp;reserved=0
> 
----------------------------------------------------------------------
For information about J forums see 
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.jsoftware.com%2Fforums.htm&amp;data=01%7C01%7C%7C784a37dd8fa340cc2fe708d6aba8a4ee%7C5090e269dbea4e98a9aa3e70be5890f7%7C0&amp;sdata=ij4WseYGXKkK4qh1SBIsc9fL3ZvA5JMMUrDoQfvQOlg%3D&amp;reserved=0
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to