Another test parsing question

(imported topic written by cstoneba)

I’m having problems with this. It doesn’t seem to be working. Is it because of the double quotes around the “CheckVers=“YES”” & “CheckVers=“NO”” ?thanks

// store the file location

parameter “filename” = “{name of drive of system folder & “\pbapps\frates\fr.ini”}”

parameter “textToReplace” = “CheckVers=“YES””

parameter “newText” = “CheckVers=“NO””

// iterate through the file replacing lines as necessary

appendfile {concatenation “%0d%0a” of ( if (it contains (parameter “textToReplace”)) then ((preceding text of first (parameter “textToReplace”) of it) & (parameter “newText”) & (following text of first (parameter “textToReplace”) of it) ) else it ) of lines of file (parameter “filename”)}

(imported comment written by MattBoyd)

hmm… maybe try something like this:

parameter “textToReplace” = “{“CheckVers=%22YES%22”}”

I did not test this, but %22 is used for escaped quotes, AFAIK.

(imported comment written by cstoneba)

No luck with:

parameter “textToReplace” = “{“CheckVers=%22YES%22”}”

parameter “newText” = “{“CheckVers=%22NO%22”}”

(imported comment written by jessewk)

This:

“{“CheckVers=%22YES%22”}”

Will end up:

“CheckVers=“Yes””

I think you want either:

parameter “textToReplace” = {“CheckVers=%22YES%22”} // will be: CheckVers=“Yes”

Or:

parameter “textToReplace” = “CheckVers=%22YES%22” // will be: “CheckVers=“Yes””

(imported comment written by cstoneba)

So here’s the strange thing. I set it back to just “CheckVers=“YES”” & “CheckVers=“NO”” and in the bigfix log file, it shows the contents of the file that I am parsing (along with the correct NewText), however, the file that I am trying to modify never changes.

(imported comment written by cstoneba)

anyone?

(imported comment written by NoahSalzman)

I had success with:

parameter “replace”=“CheckVers=“YES””

parameter “new”=“CheckVers=“NO””

And, yes, the fact that we allow those non-escaped double-quotes is weird. (Just my personal opinion.)

Also, make sure you check for case-sensitivity issues.

(imported comment written by cstoneba)

Same thing. It shows it correct in the bigfix log file, but never updates the actual file. Can you provide your appendfile command?

(imported comment written by NoahSalzman)

Is your Action Script in the first post your complete script? It is missing

copy “{parameter “filename”}” “{parameter “filename” & “.bak”}”

delete “{parameter “filename”}”

copy __appendfile “{parameter “filename”}”

(imported comment written by cstoneba)

Yup, that was it. thanks Noah. I was missing those 3 lines. I was wondering how the action modified the file.

thanks again.

(imported comment written by khanand91)

hi,

i’m trying to figure the best way to remove the unwanted CRLF at the end of a text file. I can see the CRLF there when I open the file in a text editor but when I search file the line in action script it doesnt seem to register … here’s the test I tried in the fixlet debugger.

if {exists lines whose (it contains “%0d%0a”) of file “C:\Program Files (x86)\BigFix Enterprise\BES Client\textfile.txt”}

appendfile TRUE

else

appendfile FALSE

endif

this gives me a blank in Q&A which must be the CRLF so the debugger can see it …

line (number of lines of it) of file "C:\Program Files (x86)\BigFix Enterprise\BES Client\Inv_scan_files\textfile.txt

and (number of lines of it) of file "C:\Program Files (x86)\BigFix Enterprise\BES Client\Inv_scan_files\textfile.txt gives me the line number of the line at the end that just has a CRLF

thanks all

(imported comment written by jessewk)

Your last expression:

(number of lines of it) of file "C:\Program Files (x86)\BigFix Enterprise\BES Client\Inv_scan_files\textfile.txt

… will only tell you the number of lines in the file.

Do you want a file with no CRLF’s in it at all or do you want to remove CRLF only from the last line?

(imported comment written by khanand91)

hi jesse, yes i was using the last example ( number of lines ) to demonstrate that the last line wwas indeed the CRLF and not any actual text. I just want to remove the CRLF from the last line ideally.

thanks

(imported comment written by jessewk)

ok. so you want to do something like this:

createfile until __ENDCREATE

{concatenation “%0D%0A” of (if (line number of item 1 of it = item 0 of it AND item 1 of it ends with “%0D%0A”) then (preceding text of last “%0D%0A” of item 1 of it) else (item 1 of it)) of (number of lines of it, lines of it) of file “c:\foo.txt”}

__ENDCREATE

delete c:\foo.txt

move __createfile c:\foo.txt