I have a text file that needs manipulating. Example data in the text file looks like--
C02324R
C02645R
F06487R
F05564R
S09687R
J03345R
Here is what needs to happen--
- Go thru each line in the text file
- If first Char is 'C', append/add a '3' to the end of the line of text.
- If first chars are 'S0' append/add a '4' to the end of the line of text.
- If first chars are 'S1' append/add a '5' to the end of the line of text.
- If first char is 'F' append/add a '5' to the end of the line of text.
- If first char is 'J' append/add a '6' to the end of the line of text.
thus, the end result data would look like--
C02324R3
C02645R3
F06487R5
F05564R5
S09687R5
J03345R6
I can easily write this in vba excel, but I'm much more inexperienced at powershell. I've tried switch, foreach and case statements, mostly from borrowed code but can't seem to make it work. Here is one way I tried it--
switch -file 'C:\MyFile.txt'
{
$_.StartsWith("C") {$_ + "3"}
$_.StartsWith("S0") {$_+ "4"}
$_.StartsWith("S1") {$_ + "5"}
$_.StartsWith("J") {$_ + "6"}
}
$data | Set-Content C:\MyFile.txt -Force*
Suggestions?