powershell - Iterate & Search for a string in child items -
i trying build powershell script iterates through list of files , searches , removes match, not having luck, here script
$path = "d:\test\" $filter = "*.txt" $files = get-childitem -path $path -filter $filter foreach ($item in $files) { $search = get-content -path $path$item $search| select-string -pattern "t|" }
at moment script returning whole content of file , not select string.
basically each file in folder have trailer record @ end i.e. t|1410
need iterate through files , delete last line, of these files 200mb+ can guide me please.
i've edited script , using following method.
$path = "d:\test\" $filter = "*.txt" $files = get-childitem -path $path -filter $filter foreach ($item in $files) { $search = get-content $path$item ($search)| foreach-object { $_ -replace 't\|[0-9]*', '' } | set-content $path$item }
i using powershell v.2
however, adding new empty line end of file leaving replace empty, how can avoid starting search bottom
-pattern "t|"
that pattern matches "t" or nothing. there nothing between every pair of characters in string. avoid usual regular expression handling of |
alternates separator, use backslash match literal |
:
-pattern "t\|"
alternately, use select-string
's -simplematch
switch stop argument -pattern
being treated regular expression.
Comments
Post a Comment