2011-02-24 27 views

回答

3
"*original file*" 
gc matchtest.txt 

$match_pat = "^(Match\stext\s)(\d+)" 
$newfile = @() 
gc matchtest.txt |% { 
if ($_ -match $match_pat) { 

    $incr = 1 + $matches[2] 
    $newfile += $_ -replace $match_pat,($matches[1] + $incr) 
    } 
    else {$newfile += $_} 
    } 

    $newfile | out-file matchtest.txt -force 

    "`n*new file*" 
    gc matchtest.txt 

*original file* 
Not match 121 
Match text 127 
Not match 123 

*new file* 
Not match 121 
Match text 128 
Not match 123