Using findstr to match files

September 23, 2015 at 09:04:40
Specs: Windows 7
I need to process a set of files and find those that satisfy the following

Line in file contains SYSTEM_MESSAGE(" (easy use findstr)

Now the hard bit
The correct text would be "SystemMessages" but I want to find all occurences where SYSTEM_MESSAGE(" is present but the text does not match "SystemMessages"

SYSTEM_MESSAGE("SystemMessage" would not match
SYSTEM_MESSAGES("aaa" would match

Thanks to anyone who can help

See More: Using findstr to match files

Report •

September 26, 2015 at 17:56:15
please be more specific. I didnt understand your question. please explain a bit elaborately, then i might be able to help you out.

Report •

October 12, 2015 at 12:32:32
Place the script in the directory where your file set is.

Lists all lines that don't contain SYSTEM_MESSAGE("SystemMessage, and only those who contain SYSTEM_MESSAGE("

@Echo off
setlocal enabledelayedexpansion
cd "%~dp0"
set output=
set flies=
:: Change arrayDelim to a suitable one if required
set arrayDelim=,
:: Default file extension is .txt, change to the desired one if needed.
:: Lists all given files in current directory
for /f "tokens=*" %%A in ('dir /b /s "*.txt" 2^>nul') do (
	set add=0
	echo FILE: "%%~nxA" [
	:: Read all lines in each file
	for /f "usebackq tokens=*" %%B in ("%%A") do (
		:: List all lines NOT containing SYSTEM_MESSAGE("SystemMessage
		for /f %%C in ('echo %%B ^| find /I /V "SYSTEM_MESSAGE(""SystemMessage"') do (
		:: Display all lines containing SYSTEM_MESSAGE(" in listed lines
			for /f %%D in ('echo %%C ^| find /I "SYSTEM_MESSAGE("""') do (
				echo     %%D
				set add=1
				:: Add line to output array
				set output=%%D!arrayDelim!!output!
	if !add!==1 (
		:: Add file to file array
		set files=%%~nxA!arrayDelim!!files!
	echo ]
echo !output!
echo !files!

As jaysarma987 said, you should be more specific when posting questions, keep this in mind next time.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ

Report •

October 13, 2015 at 00:10:02

I can take it from here!!

Report •
Related Solutions

Ask Question