Join Files on Country Code and Summarize by Region

Input File 1 - Sales.txt
US 100
UK  50
GR   1
US  39
ES  90
CN  29
GR   3
MX  44
UK  12
JP   5
Input File 2 - CountryCodes.txt
ES Spain           Europe
UK United Kingdom  Europe
MX Mexico          North America
US United States   North America
GR Greece          Europe
CN China           Asia
JP Japan           Asia
Sort Control Cards - SalesByRegionCtl.txt
 JOINKEYS FILE=F1,FIELDS=(1,2,A) * sales
 JOINKEYS FILE=F2,FIELDS=(1,2,A) * country code file
 REFORMAT FIELDS=(F2:20,16,F1:3,4) * Copy Region to sales
 SORT FIELDS=(1,16,CH,A) * Sort by Region
 SUM FIELDS=(17,4,ZD)
 END
Command Line
> ahlsort SalesByRegionCtl.txt "Sales.txt,dcb=(RECFM=T,LRECL=6),CountryCodes.txt,dcb=(RECFM=T,LRECL=32)" SalesByRegion.txt
Output File - SalesByRegion.txt
Asia            0034
Europe          0156
North America   0183
Back to Examples