Solved

Search and insert text with group of files

Posted on 2004-04-23
7
243 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
Comment Utility
...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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 11

Expert Comment

by:griessh
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi lbertacco

Thank you for you help :)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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 …

762 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

5 Experts available now in Live!

Get 1:1 Help Now