Download - 20120518 power shell_文字處理及輕量測試
![Page 1: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/1.jpg)
文字處理及輕量測試Jason
![Page 2: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/2.jpg)
字串建立字串只需用一對單引號’’或雙引號” “
![Page 3: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/3.jpg)
字串利用 backquote
![Page 4: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/4.jpg)
Insert String
![Page 5: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/5.jpg)
Insert String
![Page 6: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/6.jpg)
-like
![Page 7: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/7.jpg)
-like
![Page 8: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/8.jpg)
-replace
![Page 9: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/9.jpg)
Get-Content$lines = Get-Content .\Test.txt$lines.GetType()
$lines[0]$lines[0..4]
![Page 10: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/10.jpg)
ParamParam($path)
$lines = Get-Content $path$lines.length $lines.GetType()
Test.ps1 .\Test.txt
![Page 11: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/11.jpg)
Get-Content StringParam($Path)
$lines = Get-Content -Path $Path$newLine = [System.Environment]::NewLine
$content = [String]::Join($newLine,$lines)$content
![Page 12: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/12.jpg)
Set-Content
$files = dir *.txtSet-Content -Value $files -Path Test1.txt
![Page 13: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/13.jpg)
Extract-Number# .\ExtractNumbers.ps1 Test.txtParam($path)$nums = Get-Content $path$numberMatcher = [regex] "\d+"
$matches = $numberMatcher.Matches($nums)foreach ($match in $matches){
if ($match.Success){
$number = $match.Groups[0].ValueWrite-Host "number:$number"
}}
![Page 14: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/14.jpg)
FindStringInFiles#.\FindString.ps1 "1" C:\powerShell *.txt
Param($query, $path, $filter)
Set-Location $path
Select-String $query $filter | select Line,FileName,Path
![Page 15: 20120518 power shell_文字處理及輕量測試](https://reader035.vdocuments.pub/reader035/viewer/2022070523/58eca7b71a28ab2a598b45b7/html5/thumbnails/15.jpg)
參考http://msdn.microsoft.com/zh-tw/magazine/
cc163430.aspx
http://technet.microsoft.com/zh-tw/library/dd125489.aspx