How to extract a named CSV field

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

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

How to extract a named CSV field

Post by DataMystic Support »

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
Post Reply