Parsing CSV file & creating new file

Hi,

I dont know how to parse huge text in 2nd column of a CSV file using BigFix action script.

Below is the content of CSV file (just an example), this file will go to each machine whichever in the CSV file & after matching hostname it should create sh file on the machine with hostname & text of 2nd column of CSV which is corresponding to the hostname.

ServerName   Script
Hostname1     # Prioritize the method of checking for revocation of the HTTPS server 
                       # certificate. You can reverse the values to swap the default order.
                       # MGSFT_HTTPS_PRIORITIZEREVOCATIONCHECKS=OCSP,CRL

                       # These settings control the caching of HTTPS server certificate checking.
                       # Default values are shown (these take effect when no settings are specified). 
                       # Lifetime is in seconds. There are parallel settings for using CRL or OCSP
                        # checking. See documentation for more information.
                       # MGSFT_HTTPS_SSLCRLCACHELIFETIME=0
                      # MGSFT_HTTPS_SSLOCSPCACHELIFETIME=0

                      # The run policy flag determines if policy will run after installation.
                      #    "1" or "Yes" will run policy after install
Hostname2    #    "0" or "No" will not run policy
                       MGSFT_RUNPOLICY=1
                      EOF
                       # MGSFT_HTTPS_SSLCRLCACHELIFETIME=0

I though I can pass the value under parameter & than do the appendfile but if I go with that content is going in one line of file not the way its in csv column.

Is there any way we can do with BigFix action script or we specifically need to work on ps or sh script to handle that.

image

You first need to know the character(s) used to indicate the implicit newlines in column 2 of each row, then split the value into substrings and rejoin those substrings using whichever character your OS uses for a newline

concatenation "%0d" of substrings separated by "???" of (<your cell of choice>)

edit as necessary to suit.

there are more than 500 hostname info with their different scripts & there could be multiple value but looking at the glance its not possible to write these },,#, any character from Ato Z, # etc. and some line even dont have anything which start new line. :frowning:

I did below relevance test in fixlet debugger which is showing the way its in column but not parsing the same way to new file.

**Q: (lines of it) whose ((line number of it) > 1) of file ("C:\Users\Administrator\Downloads\scripts.csv")**
**A: Hostname1,# Prioritize the method of checking for revocation of the HTTPS server **
**A: # certificate. You can reverse the values to swap the default order.**
**A: # MGSFT_HTTPS_PRIORITIZEREVOCATIONCHECKS=OCSP,CRL**
**A: **
**A: # These settings control the caching of HTTPS server certificate checking.**
**A: # Default values are shown (these take effect when no settings are specified). **
**A: # Lifetime is in seconds. There are parallel settings for using CRL or OCSP**
**A: # checking. See documentation for more information.**
**A: # MGSFT_HTTPS_SSLCRLCACHELIFETIME=0**
**A: # MGSFT_HTTPS_SSLOCSPCACHELIFETIME=0**
**A: **
**A: # The run policy flag determines if policy will run after installation.**
**A: #    ""1"" or ""Yes"" will run policy after install**
**A: #    ""0"" or ""No"" will not run policy**
**A: MGSFT_RUNPOLICY=1**
**A: EOF**

and therein lies your problem - you have the information in your source spreadsheet, but saving as .csv is stripping out the information that ties all of the lines of each ‘command file’ cell together.

I’m struggling to work out the background for this - you will be sending each client a huge file with the scripts for all your servers. The overhead of managing the master .csv file, distributing it and then parsing it seems very unwieldy to me.

yes thats true & I am completely agree on that hence side by side I am working to find another way to send just one file or createfile over the fly rather than downloading it but again problem is to split it and working on each script , which is longer path as of now.

Another thought we have that server owner will keep one such script on their server at specific location & our action script will call it for whatever the purpose.

but as of now our hope is to get this file parsed & create script from it.

1 Like