G'Day,
Since discovering again the joys of using AWK/GAWK for text processing, I am updating my processes for generating the files needed for import of AWARD data into Logic. Time is too short for manual tasks.
If you have any lists you wish were in Logic, post a reference to them here, and I will do my best to create an AWK script for importing the data into Logic.
The script below is for JA - JCG, and takes the original file and processes it in ONE step - an absolute minimum of manual intervention. I will post additional scripts here as I implement them for my own use.
The script looks complex, but once one is familiar with AWK/GAWK and "regular expressions", the script is simple to follow.
After installing Gnu Win32 GAWK, the script listed below is run from the Windows command prompt like this ...
Quote:gawk -f JCG.awk <"jcg-list.txt" >jcg.txt
The jcg.txt file output is imported into Logic using Tools, Advanced, Database Commands like this ...
Quote:use lists
append from C:\Users\peter\Documents\Logic9-Data\jcg.txt delimited with TAB
Field type, and "deleted" status, are included in the output file. As a general rule the list will have a name like JCG2, and can, once validated, replace the existing list by deleting the old list and renaming JCG2 in the Tools, Setup, Lists of valid values. This is simply the technique I use. You can edit the script as appropriate.
I am simply sharing the technique I use to extract the list for Logic from the original at
JCGMy old technique took hours - with lots of editing of the original file format. This script cuts the time down to seconds - literally - and the general technique is applicable to many lists of a similar type. I don't bother looking for changes in a list - I just download the new list, and process and re-import the complete updated list into Logic.
Peter VK4IU
AWK/GAWK script for JA - JCG
Quote:
BEGIN {
debug=0; # 1=>print lots; 2=>print extension line; 3=> print complex completion
extend_list = ""; # No extension possible for the first line
seen_code = 0; # Code lines are printed in arears
jcg_code = "^( |\\*)+( |\\t)+([0-9]+)[ \\t]+([A-Za-z()]+)[ \\t]*(.*)[ \\t]*$"
}
function output_jcg(flag)
{
if (debug == 3) { print flag }
if (extend_list == "") {
if (seen_code) {
print "JCG2\t" toupper(arr[3] "\t" arr[4] " (" prefecture ")" status); # Create CSV line for Logic
}
} else {
print "JCG2\t" toupper(arr[3] "\t" arr[4] extend_list " (" prefecture ")" status); # Create CSV line for Logic
extend_list=""
}
}
/^[ \t]*$/ { # Blank line
output_jcg("blank Line");
seen_code = 0;
NEXT; # coninue with next line
}
/^[A-Z]*[ \t]+[0-9]+$/ { # Prefecture line? "AAAAAAAA NN"
if (debug == 1) { print $0 }
line=$0;
sub(/^ */, "", line);
match(line,/^([A-Z]*)[ \t]+([0-9]+)$/,arr); # Break out the data - remember some for code lines
prefecture = toupper(arr[1]);
sub(/^[\t ]*/, "", prefecture); # Remove leading spaces
sub(/[\t ]*$/, "", prefecture); # Remove trailing spaces
prefecture_code = toupper(arr[2]);
sub(/^[\t ]*/, "", prefecture_code); # Remove leading spaces
sub(/[\t ]*$/, "", prefecture_code); # Remove trailing spaces
jcg_code = "^( |\\*)+( |\\t)+(" prefecture_code "[0-9]+)[ \\t]+([A-Za-z()]+)[ \\t]*(.*)[ \\t]*$"; # Remember code prefix
if (debug == 1) { print prefecture ":" prefecture_code ":" jcg_code }
}
$0 ~ jcg_code { # jcg code line
if (debug == 1) { print $0 }
output_jcg("New code");
seen_code = 1
match($0,jcg_code,arr); # Break out the data
# [1]= deleted flag [2]= nothing [3]=jcg code [4]=name [5]=deleted when?]
sub(/^[\t ]*/, "", arr[3]); # Remove leading spaces
sub(/[\t ]*$/, "", arr[3]); # Remove trailing spaces
sub(/^[\t ]*/, "", arr[4]); # Remove leading spaces
sub(/[\t ]*$/, "", arr[4]); # Remove trailing spaces
status = "\tC\t\tF"
if (debug == 1) { print arr[1] ":\t" arr[3] ":\t" arr[4] ":\t" arr[5] }
if (arr[1] == "*") {
status = " DELETED " arr[5] "\tC\t\tT"; # Update deleted status
}
}
/^( |\*)+( |\t)+([A-Za-z()]+)[ \t]*$/ { # JCG extension line
match($0,/^( |\*)+( |\t)+([A-Za-z()]+)[ \t]*$/,extend)
extend_list=extend_list "," extend[3]
if (debug == 2) { print extend_list }
}
Peter VK4IU
You can help by posting images of
any errors and including your
Logic version.