Author Posts

September 18, 2014 at 5:36 am

I need to be able to take the data below and get into a db or .csv. Issue is the data isn't delimited at all. Its just line after line of 166 characters (17 columns without headings).

Data example
01/30/14 09:56:23 Data Received: 300114 0956 00824 9 12345 111 111 111 0 0 12345
01/30/14 09:56:23 Data Received: 300114 0956 00553 9 12345 111 111 111 0 0 12345
01/30/14 09:56:23 Data Received: 300114 0956 00136 7 1 111 01234567890# 12345 111 0 0 12345
01/30/14 09:56:23 Data Received: 300114 0956 00016 9 12345 1234567890 111 111 0 0 12345 1234567890

Below replaces the whitespace with commas, but all on one line. Is it possible to do this so the lines stay in tact inputting commas?

((Get-Content "$Env:USERPROFILE\Desktop\test.txt") -split '\s+' | Foreach-object { "$_" } ) -join ',' | out-file "$Env:USERPROFILE\Desktop\test2.txt"

Thanks

September 18, 2014 at 6:19 am

Hi. I made some modifications to your command. The problem is that you were were splitting the whole file by Space and not doing it line by line. Now it should be OK:

get-content "$Env:USERPROFILE\Desktop\test.txt" | ForEach-Object { add-content -path "$Env:USERPROFILE\Desktop\test2.txt" -value $_.replace(' ',',')}