Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find files NOT containing a defined text and output their names into a file?

Tags:

batch-file

I am having an application folder with sub-folders and thousands of files in it. I want to write a batch script which lists all the files which DO NOT contain particular text, say SAMPLE_TEXT and redirect output to a file. Please help with the script.

like image 963
Vishal Kukreja Avatar asked Mar 19 '23 20:03

Vishal Kukreja


1 Answers

Inspired by http://tobint.com/blog/powershell-selecting-files-that-dont-contain-specified-content/ this powershell worked well for me;

Get-ChildItem -include *.sql -recurse | ForEach-Object { if( !( select-string -pattern "USE " -path $_.FullName) ) { $_.FullName}} > FilesMissingUse.txt

In my case I was searching for database scripts (.sql files) which were missing "USE " string.

like image 179
PST Avatar answered May 07 '23 01:05

PST