Upload
learningtech
View
349
Download
0
Embed Size (px)
Citation preview
文字處理及輕量測試Jason
字串建立字串只需用一對單引號’’或雙引號” “
字串利用 backquote
Insert String
Insert String
-like
-like
-replace
Get-Content$lines = Get-Content .\Test.txt$lines.GetType()
$lines[0]$lines[0..4]
ParamParam($path)
$lines = Get-Content $path$lines.length $lines.GetType()
Test.ps1 .\Test.txt
Get-Content StringParam($Path)
$lines = Get-Content -Path $Path$newLine = [System.Environment]::NewLine
$content = [String]::Join($newLine,$lines)$content
Set-Content
$files = dir *.txtSet-Content -Value $files -Path Test1.txt
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"
}}
FindStringInFiles#.\FindString.ps1 "1" C:\powerShell *.txt
Param($query, $path, $filter)
Set-Location $path
Select-String $query $filter | select Line,FileName,Path
參考http://msdn.microsoft.com/zh-tw/magazine/
cc163430.aspx
http://technet.microsoft.com/zh-tw/library/dd125489.aspx