complex command shell script

I was really busy the other day and got some critical info I would need in a few days. So I opened notebook and typed in a few lines of text and wrote it. I need that file now but I cannot recall where I wrote that file or what I titled it. I don't need books or apps, I just need to know how to do this in windows. I'm certain windows is able to do this, I just don't know how. You guys are such sticks in the mud! :) Is that enough info? I know how to do this in no time under unix/linux, but not with windows. I need a windows command line sequence that will find all files that meet all following requirements:

  1. search entire c: drive
  2. file names are in the form *.txt
  3. contents are not bigger than 1k
  4. the files contain the string "specified string" The specified string can be anything

I can easily do this in one long line in linux, but in windows I'm stumped

1 answer

  • answered 2020-10-30 01:14 puravidaso

    You do this with Powershell. Example:

    (Get-ChildItem .) | ForEach-Object {
      if ($_.Name -match '.*something.*\.txt' -and $_.length -gt 15) {
        $_.FullName
      }
    }
    

    Powershell is object based instead of text based, and therefore more powerful.