1

Hi i searched few older posts but didnt find exact solution. so posting new question.

I need a single a windows command to search two words using AND condition. Will findstr works for combination of words? im searching for WORD1 followed by WORD2.( not in reverse. word2 followed by word1 or single word).

Below one is sample file contents:

TABLEA
insert
INSERT TABLEA
update tableA
upsert tableb
insert into tableA
update staging.tableA
insert into staging.tableA
-- insert into staging.tableA
test insert staging.tableA
tableA insert
tableA select insert

Desired Search Output: prints the filename when match is found. fr example, word1=insert and word2=tableA. below are the sample search results

INSERT TABLEA
insert into tableA
insert into staging.tableA
-- insert into staging.tableA
test insert staging.tableA

And i have thousands of files to search and huge in size. i need filenames which contains the match of two words.

I tried using findstr command. but not succeeded.Is there any equivalent command to use in batch file?

Thanks in advance.

2
  • Must you use batch only? Or is PowerShell acceptable?
    – jscott
    Commented Jul 20, 2016 at 0:58
  • i am working on batch file. when i call powershell inside batch, batch file runs very slow. and some unwanted text messages appears. So i prefer batch file only.
    – srinath
    Commented Jul 20, 2016 at 1:00

1 Answer 1

2

Given your exemple i was able to produce the expected result :

type sample.txt | FINDSTR /I "insert.*.tableA"

Assuming :

  • sample.txt contains the sample file content you provided
  • word1=insert and word2=tableA in correct AND order ("insert.*.tableA")
  • insensitive case (/I) to match INSERT TABLEA

I've not tested every use cases, but should be a good start for you to improve.

From now, it's up to you to parse some rules files and pass variables to the command above, this is another story but not a findstr issue.

2
  • krisFR, i tried.. FINDSTR /I "insert*tableA" *.txt .. Thanks for your help. its working.
    – srinath
    Commented Jul 20, 2016 at 2:15
  • ANy idea, how can I get colors for matched strings? and when I use combinations, batch is very slow. findstr /M /A:0C /I "insert.*ACTIVITY" *.dsx. My files are huge in size. assume 30k lines per file. Around 2k files are there to be search.
    – srinath
    Commented Jul 20, 2016 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .