Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Data sorting problem
Pages: [1] Print
Author Topic: Data sorting problem  (Read 331 times)
leke
Jr. Member
**
Offline Offline

Posts: 92


View Profile WWW
Data sorting problem
« on: April 15, 2005, 01:14:16 AM »


WORKING IN CONSOLE MODE -

I am trying to remove all the words before (or including) the first '* on each line of a text file like this:

aktivitet *  activity * toiminta
aktivkort *  smart card * älykortti
alternartivknapp *  option button * valintapainike
anpassare, adapter *  adapter * sovitin
användare *  user * käyttäjä
...

to get a result like this:

activity * toiminta
smart card * älykortti
option button * valintapainike
adapter * sovitin
user * käyttäjä
...

I tried  

Code:
txt: read/lines %text-file.txt

and messed around with PARSE and then some FOREACH loops with REMOVE; first, head and /1 but couldn't get the result I wanted.

Any Help Please!



I also need to get a similar result with:

Code:
<P><B><A name=5387>aiming symbol</A></B> valotähtäin<BR>

to read

aiming symbol => valotähtäin

although I should be able figure it out for myself as soon as I know how to do the first question.

Logged

CarlRead
Full Member
***
Offline Offline

Posts: 105


View Profile
Data sorting problem
« Reply #1 on: April 15, 2005, 02:51:04 AM »

Does this work...
Code:
txt: read/lines %text-file.txt
foreach str txt [remove/part str index? find str "*"]
?

Add a NEXT before the FIND if you want to remove the space after the "*".

The above assumes there will always be an "*" in each line.  If that's not the case you'll have to check for FIND returning a none.  ie, use something like this...
Code:
txt: read/lines %text-file.txt
foreach str txt [if found: find str "*"[remove/part str index? found]]
Hope that helps.
Logged

- Carl Read
leke
Jr. Member
**
Offline Offline

Posts: 92


View Profile WWW
Data sorting problem
« Reply #2 on: April 18, 2005, 02:59:28 AM »

Thanks Carl, but I couldn't get it working (even with next).

I get -
** Script Error: index? expected series argument of type: series port
** Near: remove/part str index? find str

for
Code:
txt: read/lines %text-file.txt
foreach str txt [remove/part str index? find str "*"]


and == none after
Code:
txt: read/lines %text-file.txt
foreach str txt [if found: find str "*"[remove/part str index? found]]


I changed it to this...
Code:
foreach str txt [remove/part str index? [next find str] "*"]
which got me past the error, but it just removed the first char of each line.

Logged

Bouba unplugged
Guest


Email
Data sorting problem
« Reply #3 on: April 21, 2005, 09:49:42 AM »

for your first one, does this fit your need?

Code:
foreach line read/lines %file.txt [
   b: parse/all line "*"
   print rejoin [b/2 " * " b/3]
]

for your html parsing, i think using load/markup may help you
manipulate the data more easily.

@+

Bouba
Logged
leke
Jr. Member
**
Offline Offline

Posts: 92


View Profile WWW
Data sorting problem
« Reply #4 on: April 25, 2005, 01:35:53 AM »

Apologies Carl, I did get

Code:
foreach str txt [if found: find str "*" [remove/part str index? found]]

to work. I didn't realise I had to add

Code:
foreach line txt [print line]

and thought == none outputted a dud.

************************************

Thanks also B

Code:
foreach line read/lines %text-file.txt [
  b: parse/all line "*"
  print rejoin [b/2 " * " b/3]
]

did the job too.
« Last Edit: April 25, 2005, 01:36:22 AM by leke » Logged

Pages: [1] Print 
Rebol Talk Forum  |  Getting Started  |  Newbie Help  |  Topic: Data sorting problem
Jump to:  

  
Quick Search...

Advanced search
  
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 20, 2008, 09:34:48 PM
Username: Password: Session Length:
  

News: 01-09-08

Alpha version of REBOL 3 has been released!


  
2287 Posts in 593 Topics by 3726 Members
Latest Member: qagilboaq

  Rebol Talk Forum | Powered by SMF 1.0.9.
© 2001-2005, Lewis Media. All Rights Reserved.

RT design by Defiant Pc