0

guys if I want like do findstr many time it just don't show the value of 2 & 3 in the line please correct me

>summary.txt (
  for %%F in (*chkpackage*) do findstr %1 "%%F" nul || echo %%F:N/A  && findstr %2 "%%F"  &findstr %3 "%%F"
)

I want to search on the string 2 and 3 too but why after I run this string 2 and 3 don't show

Did i use some syntax wrong?

like if in my resource text file have "

aaa 111 
bbb 222 
ccc 333 
DDD 444 
eee 555 
aaa 666 

sting1 for aaa
sting2 for ccc
sting3 for eee

result in summary.txt would be like

filename.txt : aaa 111 : ccc 333 : eee 555 
filename.txt : aaa 666 : ccc 333 : eee 555

Thank you for any answer

Andriy M
  • 76,112
  • 17
  • 94
  • 154
eathapeking
  • 329
  • 2
  • 6
  • 17
  • 1
    Thank you for providing the expected output. But what is the corresponding input and what are the search terms you would be using to try to get the specified output? – Andriy M Feb 18 '13 at 07:50
  • input is like abc.abc for string1 & 2 & 3 i just want to find the line that contain this 3 word and sum it then write to text file for later use in my excel( i used it with VBA) – eathapeking Feb 18 '13 at 08:00
  • What kind of logic are you trying to implement with the multiple FINDSTR calls? Is it `string1 AND string2 AND string3` or `string1 OR string2 OR string3` or something else, perhaps? It *seems* like ANDs all the way, but I'm not sure, even less so since you are saying it's not working as expected. – Andriy M Feb 18 '13 at 08:03
  • Oops, you seem to have answered my question while I was writing it. So it's ANDs, right? I.e. it should be the line(s) containing *all three* of the terms, correct? – Andriy M Feb 18 '13 at 08:05
  • Yes it AND :D i want to AND first – eathapeking Feb 18 '13 at 08:49
  • i think it's not ORs and ANDs ... How do i put this T^T it like a new search for new string line but get the output sum up into 1 line – eathapeking Feb 18 '13 at 08:52
  • Oh, I see, seems clear now, thanks! My current answer isn't a solution then. I'm removing it and will try to think of something more helpful. – Andriy M Feb 18 '13 at 08:56
  • Your Solution is it like search for any lines that contain this 3 string right? am i understand correct – eathapeking Feb 18 '13 at 08:59
  • 1
    Yes, I thought at first that you wanted one line that contained all three arguments. – Andriy M Feb 18 '13 at 09:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/24691/discussion-between-andriy-m-and-eathapeking) – Andriy M Feb 18 '13 at 09:07
  • This thread may be helpful: [Combining multiple .csv files into one .csv file line wise using a batch file](http://stackoverflow.com/questions/13985202/combining-multiple-csv-files-into-one-csv-file-line-wise-using-a-batch-file). – Andriy M Feb 18 '13 at 09:53
  • The idea behind using the solution posted on that question is to have three FINDSTR outputs, one per every search term, then join the results using a method similar to that in the answer. – Andriy M Feb 18 '13 at 10:02
  • yes seem like i have to use that method – eathapeking Feb 18 '13 at 11:32

1 Answers1

1

Perhaps is this what you want?

@echo off
for %%F in (*chkpackage*) do (
   for /F "delims=" %%a in ('findstr %1 "%%F"') do (
      for /F "delims=" %%b in ('findstr %2 "%%F"') do (
         for /F "delims=" %%c in ('findstr %3 "%%F"') do (
            echo %%F : %%a : %%b : %%c
         )
      )
   )
)
Aacini
  • 65,180
  • 12
  • 72
  • 108