Solved

Search and insert text with group of files

Posted on 2004-04-23
7
253 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
listing all functions in JavaScript 19 217
Rubik's Cube Code for Effective Presentation 3 61
ejb wildfly example 2 25
Math Equation 23 105
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

828 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