Hi how do i replicate this BASH script into powershell? It is taking a basic string and grabbing these certain chunks and putting a pipe inbetween and writing it out to the csv file. I know how to do the get-content and the output to the csv but what is the best way to chop up a string in powershell?
`cat /app/$filename |cut -c1-9,19-138,139-198,199-238,239-240,241-245,287-296 --output-delimiter="|" >> /app/CSVs/$filename.csv`
I've used split() before but it doesn't seem like the correct way to do it. I'm thinking along the lines of looping through each line and saving each piece of that line and saving to a new string var and adding the delimiter for each section. This seems awfully inefficient.
Thoughts?
The source file is structured by character position with lots of spaces. each field has a set amount of character spaces. (It's basically a database file but in really simple txt format)
1-9 = ID (9 chars long)
19-138 = business_name (120 chars long)
139-198 = address (60 chars long)
198-237 = city (40 chars long)
238-239 = state (2 chars long)
240-244 = zip_code (5 chars long)
286-295 = phone (10 chars long)
I think using $string.substring(char#,length) will work with looping but the more help the better.
The output should look like
123456789|acme business <lots of spaces>|1234 main st <lots of spaces>|etc...