changing the first occurrence only of a string in a line

Peter Alcibiades palcibiades-first at yahoo.co.uk
Fri Jun 19 02:33:51 EDT 2009


How would you do the following in Rev?

We have a file consisting of records with tab separated fields.  Each field 
has a tag followed by contents.  Some tags occur more than once in some 
records which thus have varying numbers of fields. Duplicates are always 
consecutive.  I want to eliminate all the occurrences of any tag except 
the first one.  The duplicate tags can occur any place in the record, but 
if they are duplicated, will always be consecutive.

Doing this in SED is not particularly difficult, but it does require going 
out to shell, and so its not cross platform.  You just change the tag 
using the local scope to something else.  SED then only changes the first 
occurrence in a record.  Then you use the global scope and change all of 
them.  Then you go back and change the first one back to what it was.  In 
fact, if using SED like this, the only thing you need it for is to do the 
local, first tag, change - once this is done, the rest can be done in Rev.  
But it would be nice to stay in Rev for the whole thing.  

Is there a way in Rev to pick the first occurence of a string in a record, 
change it and not subsequent occurences, and then move on to the next 
record and do the same thing? 

That is, mimic the 'local' editing mode of SED?  

Bet you all thought them dinosaurs like SED had to be extinct by now!  But 
no, they are still trampling around in the swamps of text manipulation....

For the sake of clarity, a record might look like this:

A aa TAB B bb TAB B bb TAB B bb TAB C cc TAB D dd TAB D dd

and what is wanted is to change the first occurrence of B to, for 
example !1, and the first occurence of D to, for example !2, or anyway 
something that will not occur by chance, to allow the subsequent editing 
to work globally on the file.  This is what SED does in local mode.

Peter



More information about the use-livecode mailing list