Exploring find command in windows

Exploring find command in windows

Search for: Exploring find command in windows

windows find command docs

Search for: windows find command docs

you will be using "for" command in association

Here are the docs for "for" command


https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find

Use the command name at the end


@rem *****************************************************
@rem Search all files of a particular kind for a specified string
@rem Turn echo off
@rem
@rem usage
@rem ******
@rem rfind flespec SomeString > output.txt
@rem
@rem Caution
@rem ****************
@rem The output can be large if there are lot of files
@rem
@rem An alternative then is
@rem rfind flespec SomeString | find "SomeString"
@rem
@rem Option detail
@rem ****************
@rem /c - count and print count
@rem /i - case insensitive
@rem
@rem How to read this command
@rem 1. Repeat the "do" command for each sub directory
@rem 2. The double %% is needed if this is in a batch file
@rem 3. Otherwise a single % will do
@rem
@rem
@rem *****************************************************

@echo off

for /r %%f in (%1) do find /i "%2"  "%%f"

By no means perfect

There ought to be a better way to do this with traditional piples!!!!


//Get the files listed full paths
dir /b /s some*.txt

//Then use a utility that prints for each file
filename:line-number:line-text

//example
dir /b /s some*.txt | fileout.bat

//now use a grep on it
dir /b /s some*.txt | fileout.bat | grep.bat search-string

function doit()
    for filename in eachline(stdin)
        fileid = Base.open(filename)
        linenum = 1
        for line in eachline(fileid)
            newline = "$filename : $linenum : $line"
            linenum = linenum + 1
            p(newline)
        end
    end
end

function doit()
    for filename in eachline(stdin)
        fileid = Base.open(filename)
        for (linenum,line) in enumerate(eachline(fileid))
            newline = "$filename : $linenum : $line"
            p(newline)
        end
    end
end