How to replace char in 2GB Text file with Powershell?


i replace "^" char ";" file correct csv format.

file size 2gb. visual studio not able open file, not process it.

i able replace 1 "^" char per row following script. every single row have such char 10 times.

i need every single"^" char replaced.

(get-content filename.txt) | foreach-object { $_ -replace "^", "," } | set-content filename2.csv


kenny_i

try this:

$infile = 'filename.txt' $outfile = 'filename2.txt'  filter replace-chars { $_ -replace '\^',';' }  if (test-path $outfile)  { clear-content $outfile }  get-content $infile -readcount 1000 |   replace-chars  |   add-content $outfile

the carat (^) reserved in regex , needs escaped literal match.

that process file 1000 lines @ time (rather 1).   should faster processing 1 line @ time,  and still keep memory consumption under control.

[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "







Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...