DOS Find command for multiple strings with spaces

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rex1664
Posts: 2
Joined: 15 Nov 2013 09:08

DOS Find command for multiple strings with spaces

#1 Post by rex1664 » 20 Nov 2013 04:42

Hello,

I am trying to create a batch script which is a simple find but I want to have the result in the order that the string exists.

Let me give an example. The following is what I have at the moment. which scans the file for ERROR then ouputs any occurrences. then moves onto the next string: WARNING and outputs any differences and so on. But when I review the output file it bears no resemblence to order of the input file since it is search for each string in turn.

%~d1
cd "%~p1"
find /N "ERROR" %1 > c:\temp.lst
find /N "WARNING" %1 >> c:\temp.lst
find /N "already on the library" %1 >> c:\temp.lst
find /N "another string with spaces in it" %1 >> c:\temp.lst

output
ERROR: first error
ERROR: second error
WARNING: first warning
WARNING: second warning

what I really want it do is do a find and give an idea of where chronologically the issue occurred e.g to have output
ERROR: first error
WARNING: first warning
ERROR: second error
WARNING: second warning

I know I can use the find command and list the strings like this and it will do what I want for strings without any spaces.
find /N "ERROR WARNING" %1 > c:\temp.lst

But the problem I have had is when I have a string I am searching for with spaces e.g. "already on the library"
I cannot do
find /N "ERROR WARNING already on the library" %1 > c:\temp.lst

because it will search for already, on, the, library separately.

Can someone please help with what to do here?

Thanks in advance,

Rex

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS Find command for multiple strings with spaces

#2 Post by foxidrive » 20 Nov 2013 04:54

This should work - it needs the case insensitive switch due to findstr bugs.

findstr /i /c:"ERROR" /c:"WARNING" /c:"already on the library" /C:"another string with spaces in it" %1 >> c:\temp.lst



Edited error: changed find to findstr

rex1664
Posts: 2
Joined: 15 Nov 2013 09:08

Re: DOS Find command for multiple strings with spaces

#3 Post by rex1664 » 21 Nov 2013 08:48

Thank you so much for your swift reply. I did try the above but it gave me the message invalid switch. But I tried alternatively with findstr and it worked perfectly.

Thanks again :D

findstr /i /c:"ERROR" /c:"WARNING" /c:"already on the library" /c:"another string with spaces in it" %1 >> c:\temp.lst

Post Reply