Parsing Complex Text Structures
By Ian E. Gorman, June 01, 2000
A pattern language that includes recursive patterns and conditional pattern matching can handle complex text structures without supplementary programming. Ian uses the OmniMark pattern language from OmniMark Technologies to do a job that might otherwise be done with tools like lex and yacc.
Jun00: Programmer's Toolchest
#!/bin/sed -f
# swap.sed
# sed: swap first two fields in a line of tab-delimited fields
# Run this program with the command
# sed -f swap.sed swap.txt
# where swap.txt is an input file with tab-delimited fields
s/^\([^ ]*\) \([^ ]*\)/\2 \1/
# Note - each blank is actually a single hard tab "\t"
# s/^\([^\t]*\)\t\([^\t]*\)/\2\t\1/
Example 3: Example 1 in sed.