A Simple Script Example
The very short script below extracts each company name and an associated contact name and account number from an input file containing the text of a series of fixed format reports and writes a record to the Map Designer for each company.
Input Data for Simple Example Script
Company: ABCorp Contact: Paige E.
Account: 2250556 Eye Color: Hazel
Company: MilliSoft Contact: William Gents
Account: 1578000 Eye Color: Brown
CXL SIMPLE EXAMPLE SCRIPT
#!djrr
BEGIN { AccountNo = 0;}
$0(3 10) ~ /Company:/ { CoName = trim($0(12 30));
Contact = trim($0(46 66));}
$0(3 9) ~ /Account:/ {AccountNo = trim($0(11 30));
accept CoName, Contact, AccountNo; }
OUTPUT FOR SIMPLE EXAMPLE SCRIPT
This script contains a BEGIN block and two additional pattern-action blocks. The BEGIN pattern-action block is executed once before any input is read. Each line in the input file is checked to see if it matches the pattern for the other two pattern action-blocks before the next line in the input file is processed.
The BEGIN pattern-action block initializes the AccountNo variable to 0. This establishes AccountNo as a numeric variable.
The second pattern-action block searches the 3rd to 10th positions of the input line for the string "Company:". If that string is found, the value in the 12th to 30th positions of the input line has the leading and trailing spaces removed and is assigned to the CoName variable. Also, the information in the 45th to 55th positions of the same input line has the leading and trailing spaces removed and is assigned to the Contact variable. Both variables are assigned with a single pattern since they are on the same input line.
The first action of the last pattern-action block searches the 3rd to 9th positions of the input line for the string "Account:". If is it found, the value in the 11th to 30th positions of the input line has the leading and trailing spaces removed and is assigned to the AccountNo variable. For this example, it is assumed that information about eye color is not needed in the output database, so there is no need to collect that information. If no action is specified concerning that information, no action will be taken. The data will be ignored.
The second action of the last pattern-action block outputs the CoName, Contact, and AccountNo variables to the Map Designer as fields. The Map Designer treats this information just as it would treat data in a structured database or file. Since no field names are specified in the accept statement, the Map Designer’s default field names, Field1, Field2, … will be used.
Last modified date: 12/03/2024