I'm trying to take some raw data at the moment with Powershell and massage it into SQL Insert Statements. The first order of business is to remove two commas at the end of each of the lines of raw data (before slapping the SQL code before and after the data). I've been playing around with the Powershell 'TrimEnd' to try to get this done but the following iterations just don't seem to be removing even the first comma from the end of the lines:
Sample 1 - (get-content -ErrorAction "Stop" source-file.txt) | Foreach-Object -ErrorAction "Stop" {$_.TrimEnd()} | out-file destination-file.sql
Sample 2 - (get-content -ErrorAction "Stop" source-file.txt) | Foreach-Object -ErrorAction "Stop" {$_.TrimEnd(',')} | out-file destination-file.sql
Sample 3 - (get-content -ErrorAction "Stop" source-file.txt) | Foreach-Object -ErrorAction "Stop" {$_.TrimEnd(",")} | out-file destination-file.sql
Sample 4 - (get-content -ErrorAction "Stop" source-file.txt) | Foreach -ErrorAction "Stop" {$_.TrimEnd()} | out-file destination-file.sql
The source-file.txt look something like this:
foo, foo1, foo2, foo3, foo4, foo5, ,
What I'm hoping to end up with is:
foo, foo1, foo2, foo3, foo4, foo5,
Times 200K
Is the problem that I'm not escaping the character or is the 'Foreach/Foreach-Object' not the way to go here? I'd like to make sure I'm going down the right path before I remove both commas at the end of the source-file.txt file.