Projekt

Allgemein

Profil

110 Umzug einer Datenbank (pg dump backup) Schulungs Test System » Replace1.ps1

[X] Lutz G, 27.06.2018 14:39

 
1

2
  
3
"---Starting---------------------------------------------------"
4

    
5

    
6
$reader      = [System.IO.File]::OpenText('C:\Temp\dumpall_xyz.sql')
7
$writer      = [System.IO.StreamWriter]   'C:\Temp\dumpall_Replaced.sql'
8
$searchFor   = ","        
9
$replaceWith = "?"      
10

    
11
[int]$count=0; [long]$bytes=0; $encoding = $null;
12

    
13
while($null -ne ($line = $reader.ReadLine())) {   
14
  
15
  $writer.WriteLine($line.replace($searchFor, $replaceWith));  
16
  
17
  if (!$encoding) { 
18
    $encoding = $reader.CurrentEncoding 
19
  } 
20
  $bytes += $encoding.GetByteCount($line)    
21
  $count++     
22
  
23
  if (($count % 10000) -eq 0) { 
24
    "Processed " + $count + " lines / " + [int] ( $bytes / 1048576) + " MB " 
25
  }
26
      
27
    
28
}
29

    
30
  # Zeile ausführen um Datei-Handle zu schließen, falls es Fehler gab.   
31
  $reader.Close(); $reader.Dispose(); $writer.Close(); $writer.Dispose();    
32

    
33
"---Done---------------------------------------------------"
34

    
35
"Processed " + $count + " lines / " + [int] ( $bytes / 1048576) + " MB " 
36

    
37

    
38
#Remove-Item  "D:\Test.tmp" -Force
39

    
40
#Rename-Item "$file.tmp" -NewName $filename
41

    
(1-1/2)