Solved

Search and insert text with group of files

Posted on 2004-04-23
7
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

739 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