How to extract a named CSV field

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

User avatar
DataMystic Support
Site Admin
Posts: 2204
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia

How to extract a named CSV field

Postby DataMystic Support » Thu Nov 06, 2014 4:53 pm

Below is the text of a TextPipe Scripting filter, which can be used to extract a named column from a text file, even when that column changes position from file to file.

Code: Select all

'the field name to extract
dim field_name
field_name = "Zip Code"
dim a
dim first_line
dim c

function processLine(line, EOL)

   a = Split( line, "," )
   if first_line then
       c = 0
      for each x in a
           'identify which field number it is
          c = c + 1
            TextPipe.logError x
            if x = """" & field_name & """" then exit for
            TextPipe.logError c
        first_line = false
        c = c - 1
    end if

   processLine = a(c) & EOL     
end function

sub startJob()
end sub

sub endJob()
end sub

function startFile()
  startFile = ""
  first_line = true
end function

function endFile()
  endFile = ""
end function

Simon Carter, - Insulin dose calculator for Type 1 diabetes - 250,000 free software downloads - send huge email attachments

Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: Google [Bot] and 1 guest