15
文文文文文文文文文 Jason

20120518 power shell_文字處理及輕量測試

Embed Size (px)

Citation preview

Page 1: 20120518 power shell_文字處理及輕量測試

文字處理及輕量測試Jason

Page 2: 20120518 power shell_文字處理及輕量測試

字串建立字串只需用一對單引號’’或雙引號” “

Page 3: 20120518 power shell_文字處理及輕量測試

字串利用 backquote

Page 4: 20120518 power shell_文字處理及輕量測試

Insert String

Page 5: 20120518 power shell_文字處理及輕量測試

Insert String

Page 6: 20120518 power shell_文字處理及輕量測試

-like

Page 7: 20120518 power shell_文字處理及輕量測試

-like

Page 8: 20120518 power shell_文字處理及輕量測試

-replace

Page 9: 20120518 power shell_文字處理及輕量測試

Get-Content$lines = Get-Content .\Test.txt$lines.GetType()

$lines[0]$lines[0..4]

Page 10: 20120518 power shell_文字處理及輕量測試

ParamParam($path)

$lines = Get-Content $path$lines.length $lines.GetType()

Test.ps1 .\Test.txt

Page 11: 20120518 power shell_文字處理及輕量測試

Get-Content StringParam($Path)

$lines = Get-Content -Path $Path$newLine = [System.Environment]::NewLine

$content = [String]::Join($newLine,$lines)$content

Page 12: 20120518 power shell_文字處理及輕量測試

Set-Content

$files = dir *.txtSet-Content -Value $files -Path Test1.txt

Page 13: 20120518 power shell_文字處理及輕量測試

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_文字處理及輕量測試

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_文字處理及輕量測試

參考http://msdn.microsoft.com/zh-tw/magazine/

cc163430.aspx

http://technet.microsoft.com/zh-tw/library/dd125489.aspx