Page 1 of 1 1
Topic Options
#33774 - 2002-12-01 10:16 AM Stripping trailing spaces
Dog Offline
Lurker

Registered: 2002-12-01
Posts: 2
Loc: Australia
I have a file generated from the mainframe which fills each line to 80 characters with spaces. The files can be around 100,000 lines which makes for a larger file than it should be. Each line of data is variable & can be from zero to 40 or 50 characters per line. Is there a way to have KiXtart remove these excess spaces. The file is read in by another app & is keeping the blank spaces in its database. I looked at RTRIM but couldn't quite master it.
thanks

Top
#33775 - 2002-12-01 10:33 AM Re: Stripping trailing spaces
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Hello and Welcome to the board.

Most of your text editors can do this very easily now days.

UltraEdit or TextPad as well as many others can do this very easily and much faster then KiXtart could perform the task.

UltraEdit
http://www.idmcomp.com/

TextPad
http://www.textpad.com/

Top
#33776 - 2002-12-01 10:35 AM Re: Stripping trailing spaces
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc [Frown]

$varafter=rtrim($varbefore)
_________________________
!

download KiXnet

Top
#33777 - 2002-12-01 10:39 AM Re: Stripping trailing spaces
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Did not say KiX could not do it, just said text editors could do it FASTER and I still say they can do it faster. [Wink]
Top
#33778 - 2002-12-01 10:53 AM Re: Stripping trailing spaces
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
doc [Frown]

this is kixtart zone.
your words are like bullets in my heart [Embarrassed]
_________________________
!

download KiXnet

Top
#33779 - 2002-12-01 10:59 AM Re: Stripping trailing spaces
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
I'm sorry boss... No harm meant, just trying to speak a little truth.

I LOVE KiXtart... and perhaps Dog needs to do this over and over, in such case, yes KiXtart may be the best tool for him.

Read the file into a variable, using the type of code Lonkero suggested. Post again Dog if you need further assistance with accomplishing this.

Top
#33780 - 2002-12-01 03:54 PM Re: Stripping trailing spaces
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Untested!
code:
IF Open(1, 'file.txt', 2) = 0
if open (2,'newfile.txt',5)=0
$line = ReadLine(1)
WHILE @ERROR = 0
$line=rtrim($line)
$rc=writeline(2,$line)
$line = ReadLine(1)
LOOP
$rc=close(2)
endif
$rc=close(1)
ENDIF

_________________________
There are two types of vessels, submarines and targets.

Top
#33781 - 2002-12-02 11:37 AM Re: Stripping trailing spaces
Dog Offline
Lurker

Registered: 2002-12-01
Posts: 2
Loc: Australia
thanks all, KiXtart will do the job however as was stated is too slow for a large file. It would work well for some smaller files. Below is the script that was tested & worked if anyone needs it.

IF Open(1,"c:\temp\Filein.txt",2) = 0
Open (2,"c:\temp\Fileout.txt",5)
$x = ReadLine(1)
WHILE @ERROR = 0
$y = Rtrim($x) + chr (10)
Writeline (2,$y)
$x = ReadLine(1)
LOOP
Close (1)
Close (2)
ENDIF

Top
#33782 - 2002-12-02 11:49 AM Re: Stripping trailing spaces
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Thanks for the reply and feedback Dog.

As a reminder, if you take a look you should see some buttons under Instant UBB Code

By placing your code inbetween the [ code ] tags it will maintain a proper code layout.

Top
#33783 - 2002-12-02 11:55 AM Re: Stripping trailing spaces
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
dog, this should do faster, give it a try:
code:
Open(1,"c:\temp\Filein.txt")
Open (2,"c:\temp\Fileout.txt",5)
$x = split(ReadLine(1))
WHILE $x
Writeline (2,$x[ubound$x)]+@crlf)
$x = split(ReadLine(1))
LOOP
Close(1)
Close(2)



[ 02. December 2002, 11:56: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#33784 - 2002-12-10 12:52 AM Re: Stripping trailing spaces
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear,

In an earlier edition of Ruud's manual (= KiXtart 4.10) you can read as remark on Open function
quote:

The file-I/O functions in KiXtart (OPEN, READLINE, and CLOSE) process small configuration files. They are not intended for larger operations, such as scanning long files. For the sake of simplicity and speed, OPEN reads an entire ASCII file into memory, and subsequent READLINE commands read lines stored in memory.

Although this design is memory-intensive, it is also very fast and simple.


greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#33785 - 2002-12-09 02:24 PM Re: Stripping trailing spaces
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
yep.
that is good.
memory intensive?
well, might be if someone thinks 20-50M is intensive.
I've seen some oracle-machines and know that is not the case.

I've used these methods for long data-tables for some 3 years by now and they are more than fast enough.
_________________________
!

download KiXnet

Top
#33786 - 2002-12-09 02:42 PM Re: Stripping trailing spaces
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Lonkero,

It is just "what is an acceptable service for someone".
Also it isn't always possible to handle it in an easy way. At this
moment it can be hard for kixtart to read lines with a length
250.000 characters. Also we shouldn't forget that I/O opera-
tion can be very CPU intensive.

We prefer a higher program language to do the job, when we want to
analyze file contents on a regular base. Sometimes we had to deal with
nearly 500 MB of data for the preparation of our statistical pages. We
wouldn't like to wait for about 1 or 2 hours for one simple run. Now it
cost only 3/4 minutes to do the job.

A good comparison was made in the past during developping our kixstrip tool.
The response time between a kixtart variant and our tool was dramatical.
greetings.
_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

Top
#33787 - 2002-12-09 02:51 PM Re: Stripping trailing spaces
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mca, that file-I/O slowness is the one thing that speaks for kixtart usage.
when really parsing whole file and maybe doing even complex edits, it's better to have the data in memory than in temp-files.

sure, using LOWER level programming gives you the speed, but not all can code that.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.074 seconds in which 0.036 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org