[SOLVED] Double quotes in csv file causing action script failure

I am trying to create a BigFix setting to use later in a property analysis, but some double quotes in my csv file are causing it to fail.

An example csv that causes my issue would be like this:

LocationNumber,LocationStreet,Market,MarketDescription,EntityName,EntityNumber
3,1234 Any St,“San Diego, CA”,NULL,“Fake Company, LLC”,2085

My test action script for this is:

setting "LDB_Headers"="{line 1 of file "C:\LDB\feed.csv"}" on "{now}" for client
setting "LDB_LineFeed"="{line 2 of file "C:\LDB\feed.csv"}" on "{now}" for client

Here are the relevant log file entries showing the error with the second line that contains double quotes:

Command succeeded setting “LDB_Headers”=“LocationNumber,LocationStreet,Market,MarketDescription,EntityName,EntityNumber” on “Mon, 10 Aug 2015 08:30:19 -0700” for client (action:2281)

Command failed (Missing ‘on’ keyword) setting “LDB_LineFeed”=“3,1234 Any St,“San Diego, CA”,NULL,“Fake Company, LLC”,2085” on “Mon, 10 Aug 2015 08:30:19 -0700” for client (action:2281)

I’ve tried surrounding by %22, using the “escapes of” relevance, adding extra quotes, but cannot get anything to work. Any help is appreciated!

Thanks,
Sean

I think you will have to percent encode your lines as you read them out?

Thanks, Alan. But I think I’m going to need a little more hand holding than that. I’m new to BigFix and relevance. I tried surrounding the retrieved line with %22, but it didn’t help. This modified line:

setting "LDB_LineFeed"="{"%22" & line 2 of file "C:\LDB\feed.txt" & "%22"}" on "{now}" for client

resulted in a similar outcome:

Command failed (Missing ‘on’ keyword) setting “LDB_LineFeed”="“3,1234 Any St,“San Diego, CA”,NULL,“Fake Company, LLC”,2085"” on “Mon, 10 Aug 2015 13:06:32 -0700” for client (action:2283)

If you have time, could you provide an example of what you have in mind? Thanks again.

I don’t do this part much but you don’t want to put percent encoded ‘"’ characters there, you need to strip the existing ‘"’ that is around the “San Diego, CA” and the “Fake Company, LLC”

I don’t have a Fixlet Debugger handy but something like:

{(if (character 0 of it = "%22") then (substring between "%22" of it) else it) of line 2 of file  "C:\LDB\feed.csv"}

As soon as I hit “send” there I realized you are trying to “set” the entire thing. So yes you need to percent encode the entire string you are reading. If someone can point to the right relevance?

You can see the issue here:

setting "LDB_LineFeed"=""3,1234 Any St,"San Diego, CA",NULL,"Fake Company, LLC",2085"" on ...
                        ^Ends the first string - so we look for "on" after that....

This is what you want

setting "LDB_LineFeed"="3,1234 Any St,@22San Diego, CA%22,NULL,%22Fake Company, LLC%22,2085" on ...

Either that or some other string manipulation.

Thanks so much, Alan. I was able to use your comments and another from @jgstew here to put this one to rest. Here is my final action script containing the fixed “LDB_LineFeed” setting:

parameter "FilePath" = "C:\LDB\feed.txt"

// Find the line in the csv that starts with a number that matches the numbered part of the name of this device (without the leading zeros). Assumes only one line in the csv matches.
parameter "LineMatch" = "{(lines whose (it starts with parenthesized part of match (regex "^0*([1-9][0-9]*|0)-\w") of (value of variable "ComputerName" of environment)) of file (parameter "FilePath"))}"

// Store the csv header and matching line to be used later.
if {(exists file (parameter "FilePath"))}
    setting "LDB_Headers"="{line 1 of file (parameter "FilePath")}" on "{now}" for client
    setting "LDB_LineFeed"="{concatenation "%2522" of substrings separated by "%22" of (parameter "LineMatch")}" on "{now}" for client
endif

Thanks again!

1 Like

Thanks for sharing.

Double escaping "'s is a mind bender.