Exploring find command in windows

satya - 9/5/2020, 12:04:11 PM

Exploring find command in windows

Exploring find command in windows

Search for: Exploring find command in windows

satya - 9/5/2020, 12:04:18 PM

windows find command docs

windows find command docs

Search for: windows find command docs

satya - 9/5/2020, 12:04:40 PM

you will be using "for" command in association

you will be using "for" command in association

satya - 9/5/2020, 12:04:54 PM

Here are the docs for "for" command

Here are the docs for "for" command

satya - 9/5/2020, 12:05:53 PM

This is a nice way to find docs at microsoft


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

satya - 9/5/2020, 12:06:16 PM

Use the command name at the end

Use the command name at the end

satya - 9/5/2020, 12:32:28 PM

Here is how to do this


@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"

satya - 9/5/2020, 12:32:41 PM

By no means perfect

By no means perfect

satya - 9/5/2020, 12:32:58 PM

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

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

satya - 9/5/2020, 2:44:48 PM

A better approach is


//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

satya - 9/5/2020, 2:45:45 PM

In Julia the fileout looks like this


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

satya - 9/5/2020, 2:57:31 PM

A better version using enumerate


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