I've been working on a perl script that reformats csv (comma seperated value) files to a format specified by the user. Ever downloaded or used a program to generate csv files that are not quite the format you wanted. Well now you can correct these files using my perl script. Obviously you need perl installed on your computer and hopefully it works with 64 bit installations
So basically what my perl script does is process all csv files (could be only 1) in the current directory where the perl script resides and outputs the resultant csv files in a sub-directory called tmp (if the directory does not exist, it will be created). What the user needs to do is edit the script to either add, delete, modify, and/or rearrange the columns they want written. The limitation is that the original input csv files must be of the same format.
So when the script is run, the following questions will be asked:
1) Output to only 1 file (y/n) ?
If "y" then all results will be stored in a single file called csvref.csv in sub-directory tmp.
Otherwise the resultant files will have the same name as their original counterparts but stored in sub-directory tmp.
2) Write New Header (y/n) ?
If "y" then a header will be written at the start of the resultant file/(s). The user will need to edit subroutine writenewheader() to correct the resultant column headers. Otherwise no header is written to the resultant file/(s).
3) Ignore First N Lines (0 = include all) :->
When processing the input csv file/(s), if the first row contains just headers then you want to skip this row so enter "1", if the second row is garbage aswell then enter "2" and so on. If no headers or garbage then set to 0. So basically N entered rows will be skipped. All input csv files must have the same number of rows to skip over or resultant data will contain misssing or garbage rows which is pretty self explanatory!
I have attached perl script csvref.pl and test input files ANZ.csv, BHP.csv & CBA.csv and will explain the code that user needs to modify in later posts. These files all need to be in the same directory for things to work.
Note: Please remove .txt extension from all files.
Cheers,
Andrew
So basically what my perl script does is process all csv files (could be only 1) in the current directory where the perl script resides and outputs the resultant csv files in a sub-directory called tmp (if the directory does not exist, it will be created). What the user needs to do is edit the script to either add, delete, modify, and/or rearrange the columns they want written. The limitation is that the original input csv files must be of the same format.
So when the script is run, the following questions will be asked:
1) Output to only 1 file (y/n) ?
If "y" then all results will be stored in a single file called csvref.csv in sub-directory tmp.
Otherwise the resultant files will have the same name as their original counterparts but stored in sub-directory tmp.
2) Write New Header (y/n) ?
If "y" then a header will be written at the start of the resultant file/(s). The user will need to edit subroutine writenewheader() to correct the resultant column headers. Otherwise no header is written to the resultant file/(s).
3) Ignore First N Lines (0 = include all) :->
When processing the input csv file/(s), if the first row contains just headers then you want to skip this row so enter "1", if the second row is garbage aswell then enter "2" and so on. If no headers or garbage then set to 0. So basically N entered rows will be skipped. All input csv files must have the same number of rows to skip over or resultant data will contain misssing or garbage rows which is pretty self explanatory!
I have attached perl script csvref.pl and test input files ANZ.csv, BHP.csv & CBA.csv and will explain the code that user needs to modify in later posts. These files all need to be in the same directory for things to work.
Note: Please remove .txt extension from all files.
Cheers,
Andrew