Solved

Search and insert text with group of files

Posted on 2004-04-23
7
252 Views
Last Modified: 2010-04-17
RE this question : http://www.experts-exchange.com/Programming/Q_20961859.html

I am using the multiple option as below       
      


find /C "<pattern1>" *.txt | find ": 0" > destFile.txt
find /C "<pattern2>" *.txt | find ": 0" >> destFile.txt
find /C "<pattern3>" *.txt | find ": 0" >> destFile.txt
find /C "<pattern4>" *.txt | find ": 0" >> destFile.txt
      


However what i would like to do is add some text with each find. For example i would like to add the text "PATTERN 1 is MISSING" if the find /C "<pattern1>" *.txt | find ": 0" > destFile.txt was missing so the results would look something like

0
Comment
Question by:gisvpn
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:lbertacco
ID: 10901477
...something like... what?

I'm not sure I understand your question properly, would this solve?

find /C "<pattern1>" *.txt | find ": 0" > destFile.txt
If Errorlevel 1 echo PATTERN 1 is MISSING >> destFile.txt
find /C "<pattern2>" *.txt | find ": 0" >> destFile.txt
If Errorlevel 1 echo PATTERN 2 is MISSING >> destFile.txt
find /C "<pattern3>" *.txt | find ": 0" >> destFile.txt
If Errorlevel 1 echo PATTERN 3 is MISSING >> destFile.txt
find /C "<pattern4>" *.txt | find ": 0" >> destFile.txt
If Errorlevel 1 echo PATTERN 4 is MISSING >> destFile.txt
0
 

Author Comment

by:gisvpn
ID: 10903392
ok no i dont think i could get that to work..

sorry im was not good explaining it..

i'll just explain using this one line.

find /C "<pattern1>" *.txt | find ": 0" > destFile.txt

The above will look through all my files and return all the file names which do NOT have the word <PATTERN1> in it.

What i would like is not only the file name but also what it was looking for, i.e <PATTERN1> with the result.

0
 
LVL 11

Accepted Solution

by:
griessh earned 500 total points
ID: 10904278
It is hard to concat the outputs of two commands.

Wouldn't it be possible to do it this way:

@echo off
echo These files are missing "<pattern1>":
find /C "<pattern1>" *.txt | find ": 0" > destFile.txt
echo These files are missing "<pattern2>":
find /C "<pattern2>" *.txt | find ": 0" >> destFile.txt

=====
Werner
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 11

Expert Comment

by:griessh
ID: 10904389
Now this would be the (almost) ultimate approach:

1st batch file 'f.bat':

@echo off
echo Missing %1%
find /C "%1" *.txt | find ": 0"

2nd batch file 'b.bat':
:TEST
if x%1==x goto END
call f %1
SHIFT
goto TEST

:END

Now you can run your search dynamically:

b aaa bbb ccc ddd

and b.bat will loop through the argument list (the SHIFT command moves the %1 to the next argument) until the argument is empty (x%1==x chacks that, it is only true if %1 is empty).

let me know ...
0
 
LVL 11

Expert Comment

by:lbertacco
ID: 10906606
This is more like your original script:

Save these 2 lines to findnot.bat
@Echo Off
For /F "tokens=2,3" %%i IN ('find /C "%1" %2') DO If "%%j"=="0" echo %%i doesn't contain "%1"

Then do:
call findnot <pattern1> *.txt > destFile.txt
call findnot <pattern2> *.txt >> destFile.txt
call findnot <pattern3> *.txt >> destFile.txt
...
0
 

Author Comment

by:gisvpn
ID: 10906611
Brilliant....

I used suggestion above and modified it a little like this and it works perfect !



@echo off
echo These files are missing "<pattern1>" > destfile.txt:

find /C "<pattern1>" *.txt | find ": 0" >> destFile.txt

echo These files are missing "<pattern2>">> destfile.txt:

find /C "<pattern2>" *.txt | find ": 0" >> destFile.txt

PAUSE




The result looks like this



These files are missing "<pattern1>"  
---------- COPY (2) OF COPY OF TEST.TXT: 0
---------- COPY (3) OF COPY OF TEST.TXT: 0
---------- COPY (5) OF COPY OF TEST.TXT: 0
---------- COPY (6) OF COPY OF TEST.TXT: 0
---------- COPY OF TEST.TXT: 0
---------- TEST.TXT: 0
These files are missing "<pattern2>"
---------- COPY (2) OF COPY OF TEST.TXT: 0
---------- COPY (3) OF COPY OF TEST.TXT: 0
---------- COPY (4) OF COPY OF TEST.TXT: 0
---------- COPY (5) OF COPY OF TEST.TXT: 0
---------- COPY (6) OF COPY OF TEST.TXT: 0
---------- COPY (7) OF COPY OF TEST.TXT: 0
---------- COPY OF COPY OF TEST.TXT: 0
---------- COPY OF TEST.TXT: 0
---------- TEST.TXT: 0


Grreat thank you for all your help !
0
 

Author Comment

by:gisvpn
ID: 10906620
Hi lbertacco

Thank you for you help :)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
My project did see openJDK that I installed. What could be the problem 7 141
Path of Workbook 3 77
numbers ascending pyramid 101 195
C# DataGridView_RowsAdded event not firing 1 75
This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question