Fun!
<cfset thistext = "options (direct=true, errors=999999)
load data
into table raw_i
append
(record_id position(1:1) CHAR,
process_mt position(2:3) CHAR,
process_yr position(4:5) CHAR,
batch_no position(6:9) CHAR,
nursery_ind position(14:14) CHAR,
county_cd position(15:16) CHAR,
section position(17:18) CHAR,
township position(19:20) CHAR,
tship_dir position(21:21) CHAR,
range position(22:23) CHAR,
range_dir position(24:24) CHAR,
base_ln_mer position(25:25) CHAR,
aer_gnd_ind position(26:26) CHAR,
grower_id position(27:37) CHAR,
cedts_ind position(38:38) CHAR,
site_loc_id position(39:46) CHAR,
acre_planted position(47:54) CHAR,
unit_planted position(55:55) CHAR,
applic_dt position(56:61) CHAR,
site_code position(62:67) CHAR,
qualify_cd position(68:69) CHAR,
planting_seq position(70:70) CHAR,
acre_treated position(71:78) CHAR,
unit_treated position(79:79) CHAR,
mfg_firmno position(80:86) CHAR,
label_seq_no position(87:91) CHAR,
revision_no position(92:93) CHAR,
reg_firmno position(94:100) CHAR,
amt_prd_used position(101:110) CHAR,
unit_of_meas position(111:112) CHAR,
document_no position(113:120) CHAR,
summary_cd position(121:124) CHAR,
file_date position(125:144) DATE ""DD-MON-YYYY HH24:MI:SS"",
file_name position(*) CHAR TERMINATED BY X'0A'
)">
<cfset positions = StructNew()>
<cfloop index="thisrow" list="#thistext#" delimiters="#Chr(10)#">
<cfif FindNoCase("position(", thisrow)>
<cfset thisname = Replace(Trim(ListFirst(thisrow, " ")), "(", "",
"ALL")>
<cfset thisstart = ListLast(ListFirst(Replace(thisrow, ":MI:", "",
"ALL"), ":"), "(")>
<cfset thisend = ListFirst(ListLast(Replace(thisrow, ":MI:", "",
"ALL"), ":"), ")")>
<cfset positions["#thisname#"] = StructNew()>
<cfif IsNumeric(thisstart)>
<cfset positions["#thisname#"].start = thisstart>
</cfif>
<cfif IsNumeric(thisend)>
<cfset positions["#thisname#"].end = thisend>
</cfif>
</cfif>
</cfloop>
On Tue, Nov 25, 2008 at 9:25 AM, Ian Skinner <[EMAIL PROTECTED]> wrote:
> How would some of you take this text file and parse it into a structure?
>
> I would like to take this text:
>
> options (direct=true, errors=999999)
> load data
> into table raw_i
> append
> (record_id position(1:1) CHAR,
> process_mt position(2:3) CHAR,
> process_yr position(4:5) CHAR,
> batch_no position(6:9) CHAR,
> nursery_ind position(14:14) CHAR,
> county_cd position(15:16) CHAR,
> section position(17:18) CHAR,
> township position(19:20) CHAR,
> tship_dir position(21:21) CHAR,
> range position(22:23) CHAR,
> range_dir position(24:24) CHAR,
> base_ln_mer position(25:25) CHAR,
> aer_gnd_ind position(26:26) CHAR,
> grower_id position(27:37) CHAR,
> cedts_ind position(38:38) CHAR,
> site_loc_id position(39:46) CHAR,
> acre_planted position(47:54) CHAR,
> unit_planted position(55:55) CHAR,
> applic_dt position(56:61) CHAR,
> site_code position(62:67) CHAR,
> qualify_cd position(68:69) CHAR,
> planting_seq position(70:70) CHAR,
> acre_treated position(71:78) CHAR,
> unit_treated position(79:79) CHAR,
> mfg_firmno position(80:86) CHAR,
> label_seq_no position(87:91) CHAR,
> revision_no position(92:93) CHAR,
> reg_firmno position(94:100) CHAR,
> amt_prd_used position(101:110) CHAR,
> unit_of_meas position(111:112) CHAR,
> document_no position(113:120) CHAR,
> summary_cd position(121:124) CHAR,
> file_date position(125:144) DATE "DD-MON-YYYY HH24:MI:SS",
> file_name position(*) CHAR TERMINATED BY X'0A'
> )
>
> And end up with a structure something like:
>
> positions.record_id.start = 1
> positions.record_id.end = 1
> positions.process_mt.start = 2
> positions.process_mt.end = 3
> ....
>
>
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:315885
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4