Re: field extraction ala awk

new topic     » goto parent     » topic index » view thread      » older message » newer message
sash said...

Hello,

Is there a straightforward way to extract fields delimited by say a colon or a comma, from a record, like it is done in AWK? It would be nice to replace my awk scripts by OEU scripts, if it was possible. smile

Thank you for suggestions.

In sequence.e there is split() and split_any(). One of these may suit your requirements. The source has examples, eg:

Example 1:

 result = split("John Middle Doe") 
 -- result is {"John", "Middle", "Doe"} 
 

Example 2:

 result = split("John,Middle,Doe", ",",, 2) -- Only want 2 sub-sequences. 
 -- result is {"John", "Middle,Doe"} 
 

Example 3:

 result = split("John||Middle||Doe|", '|') -- Each '|' is significant by default 
 -- result is {"John","","Middle","","Doe",""} 
 result = split("John||Middle||Doe|", '|', 1) -- Adjacent '|' are just a single delim, 
                                              -- and leading/trailing '|' ignored. 
 -- result is {"John","Middle","Doe"} 
 

Spock

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu