Using PARSEARGS to split fields
Posted in 1991
A tip on tool to solve this problem: Using ESQL/C I needed to extract data from various tables and then pass this data through a series of programs that massaged/calculated various items along the way. I wanted the programs to operate on textual delimited fields. Such as, |FLD1|FLD2|10|5.5|.... etc. output could then be loaded into a table if required or passed to the next program in a series of steps. Many standard Unix utilities can also be used as required. A necessary function is the ability to parse the fields from a delimited string and convert into an appropriate data type. Here's the tip. Brad Appleton posted an update/rewrite to the PARSEARGS utility discribed by Eric Allman's article in UNIX Review. PARSEARGS will do a lot more than parse arguments from the program command line. Parsing a data string like I just described is no big deal. PARSEARGS is table driven. You basically need to describe each field in the table along with its data type. Slightly massage the input string using some PARSEARG routines and call the parsearg function. Other neat stuff is possible... |FLD1-part1 FLD1-part2|-x -c 10 -t yes|FLD2|10|5.5| Each output string can include a Unix command like string that contains options affecting this record only. After the string is parsed out you can call a PARSEARG function using the string and a differently defined argument table. |FLD1|FLD2|10|FLD4-1|FLD4-2|FLD4-3|FLD4-n|..... where n = value of 3rd field. we are currently learning other PARSEARG techniques in order to parse a variable number of fields. End of tip. If anyone would like additional discussion of this feel free to write. Michael J. Kuhn Consultant phone :301-254-7060 e-mail :c/o Baltimore Rh Typing Laboratory, Inc. phone :301-225-9595 uunet!rhlab!kuhn