logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Lists of valid values - import to Logic
vk4iu
#1 Posted : Sunday, April 21, 2013 2:45:55 AM(UTC)
VK4IU

Rank: Advanced Member

Groups: Moderator, Registered, Administrators
Posts: 404
Man
Location: Hodgleigh QLD

Thanks: 6 times
Was thanked: 77 time(s) in 68 post(s)
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 JCG

My 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.
1 user thanked vk4iu for this useful post.
WN4AZY on 4/22/2013(UTC)
Sponsor
Note: We receive a commission from Amazon when you purchase via this link. It does not affect your cost. Thank you!
WN4AZY
#2 Posted : Monday, April 22, 2013 9:48:58 AM(UTC)
admin

Rank: Administration

Groups: Administrators, Beta Testers
Posts: 3,097
Man
Location: Auburn, GA

Thanks: 998 times
Was thanked: 497 time(s) in 412 post(s)
Thanks Peter!

Here I think is the link to jcg-list.txt:
http://www.jarl.or.jp/En...-5_jcc-jcg/jcg-list.txt


And GAWK:
http://gnuwin32.sourceforge.net/packages/gawk.htm

I will look into using GAWK by LOGic to import the point-n-click stuff. It would be simpler to update a GAWK script than change the code every time they change the list format.

Many tnx & 73,

Dennis
Users browsing this topic
Guest (4)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.5.5 | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.052 seconds.