Re: field extraction ala awk
- Posted by Spock Feb 24, 2019
- 1138 views
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.
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