Solved

Search and insert text with group of files

Posted on 2004-04-23
7
248 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now