How to extract specific columns/line items from a CSV file?

Keith Clarke keith.clarke at me.com
Tue Sep 20 17:14:47 EDT 2016


Thanks Mike (& Craig) for confirming that iteration of some sort is the way to go. 

It’s interesting that the url container can be addressed directly, instead of loading the file - I’d not seen that before. I’m currently pulling each file into a regular variable, so will probably stick with that as only a few (existing) lines of code would be saved and the net overall effect on timing / resources is probably marginal if the file gets loaded behind the scenes anyway.

As the column names/numbers vary by CSV file name - which I have built-out in a ColumnsOfInterest field - it looks like I’ll also be safe to iterate through these items to build the row extraction line dynamically, too.

Great, thanks again - I have a direction of travel.
Best,
Keith..
   
> On 20 Sep 2016, at 21:32, Mike Bonner <bonnmike at gmail.com> wrote:
> 
> If a file you can do this..
> 
> repeat for each line tline in url "file:yourfilename.csv"
> put item 1 of tLine & comma & item 3 of tline & comma & item 15 of tLine &
> return after tExtracted
> end repeat
> delete the last char of tExtracted -- remove the extraneous return
> 
> Or you can put them into an array or whatever. It should be VERY fast.  If
> the files are very large, you can instead open the file for read, read a
> line, extract the data as above, and repeat till the end of the file. I
> think using repeat for each with a file url loads the whole thing at once
> then goes line to line, but I'm not sure of that.
> 
> On Tue, Sep 20, 2016 at 2:16 PM, Keith Clarke <keith.clarke at me.com> wrote:
> 
>> Hi folks,
>> I’ve a large number of sizeable CSV files from each of which I need to
>> extract just 2 or 3 specific columns. Creating nested iterations through
>> every item in every line seems somewhat inefficient - as does loading each
>> full file into memory - so I feel I must be missing a trick here.
>> 
>> Does Livecode support any elegant way of directly manipulating or
>> ‘querying’ (like SQL) delimited data, to extract numbered (or named)
>> columns/items - such as 1(Id), 3(Name) & 15(Summary) - from in each line
>> from a CSV container or direct from a file/URL?
>> Best,
>> Keith..
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list