piping get-childitem into select-string in powershell -
i sorting large directory of files , trying select individual lines output of ls command , show only, weird results , not familiar enough powershell know i'm doing wrong.
this approach works:
ls > data.txt select-string 2012 data.txt rm data.txt but seems wasteful me create file read data have fill file. want pipe output directly select-string.
i have tried approach:
ls | select-string 2012 but not give me appropriate output.
my guess need convert output ls select-string can work with, have no idea how that, or whether correct approach.
powershell object-oriented, not pure text cmd. if want fileobjects(lines) modified in 2012, use:
get-childitem | where-object { $_.lastwritetime.year -eq 2012 } if want fileobjects "2012" in filename, try:
get-childitem *2012* when use
ls | select-string 2012 you're searching lines "2012" inside every file ls / get-childitem listed.
if need use select-string on output get-childitem, try converting strings, splitting lines , search it. this:
(get-childitem | out-string) -split "`n" | select-string 2012
Comments
Post a Comment