在Scripting Guy專欄中
http://www.microsoft.com/technet/scriptcenter/resources/qanda/may07/hey0517.mspx
本篇是要從資料中取出電話
因為電話有一定的格式所以利用regular expression是不錯的選擇

上述問題若使用PowerShell來解的話
可以透過以下的指令

#設定regular expression
$Pattern = [regex]'\d{3}-\d{3}-\d{4} \([a-zA-Z]*\)'
#將內容合併成一行,解析內容,最後儲存結果
$Result = $Pattern.Match([string]::Join(";",@(get-content d:\1.txt))) | foreach{ $n = $_; while($n.Success){$n.Value;$n = $n.NextMatch()} }

arrow
arrow
    全站熱搜

    ayowu 發表在 痞客邦 留言(0) 人氣()