A friend of mine in finance posed an interesting question to me that I had never attempted before the other day. It quickly became evident that it would be alot of work so PowerShell came to mind. Here’s the short of it.
He has some finance application that he exports some sort of report from on a regular basis. He needs to combine/merge portions of the CSV files and analyze the data. The report comes in the form of a CSV (yippee!!). The problem is the format of the CSV (booo!!). The first column and the first 12 rows is all garbage. Essentially, I have many CSV files (100s) that I need to delete the first column and the first 12 rows then I can work with the good data.
[/quote]
I suspect you already tried that ... I think a better way would be to use Import-Csv and pipe it to Select-Object Skip 12 as it deals with the CSV headers if there are some.
[quote quote=158553]
I haven't found a method to remove the first column, any ideas on that piece?[/quote]
Depending on the amount of headers / columns you can use Select-Object for this purpose as well. You simply specify all headers / columns as properties you like to keep ... that's all.
Unfortunately, changing the source output is not an option. It’s a 3rd party app that we don’t control or have access to, we get what we get as far as reports are concerned.
Below is what the actual CSV looks like, they are all formatted the same way. I need to grab the data in B13:M13 down each row and discard the rest of the stuff in the CSV.
What you have there is not a valid CSV file though - you will have to make one of it first. So your approach to skip the first 12 lines seems to be valid in this case.
You could save the result of this “operation” as CSV file with pipeing it to Out-File and treat it as such from this moment.
Regardless of that - most of the time an image of code or example data is not that helpful. If you post code or sample data you should format it as code. That’ll prevent unwanted line breaks and makes it possible to copy and to test your code or sample data.
Ok, so I’ve managed to get some viable results to the console. This code returns the correct results to the console but I can’t seem to figure out the getting them to a CSV. Export-CSV does not give the expected output and out-file outputs the correct data but it’s all comma separated in the same cell in the each row of the CSV
So you remove the first 13 lines and save the rest of the file to a new file with a new name. Then you can proceed with this newly created, hopefully valid CSV files.
You might adjust the -Delimiter to your files but it should give you the pure data part of your CSV files.
That does what I need it to do, drops C1 but seems really inefficient. It appears I have to import all the columns then select just the ones that I want to maintain the data structure.