Another Batch Grep Sed problem

Hi All;

Again another batch file to write for a stupid reason, but hey ho.

What i am trying to do is find out a version of a poorly written application a certain machine is running.
the only differential i can find is a xml file. there are two different versions, the old version does not contain the following string;
<SystemVersions>

What i propose todo is create an output file if the string exists/or doesn’t, after which i can poll these machines, and the ones that fail to bring back a file have either the new/old version of this application.

To do this i have started down this route, but failing at the end.


grep <SystemVersions> afile.xml >version.txt
cat version.txt |find “<SystemVersions>”> nul
if errorlevel=0 goto bad
else goto good
:bad
exit
:good
echo good >good.txt
exit

I know i have syntaxt issues, but just wanting to know if i am going about this the right way or not?

Cheers all!

bit confused what you’re trying to achieve but I’ll take a stab (that find command is particularly odd :wink: )

the initial grep is fine… that’ll create either a file containing the string you’re looking for or a blank file with nothing in it.

you should be able to do a


grep "<SystemVersions>" afile.xml > version.txt
if (test -s version.txt)
  do
    echo "good" > good.txt
    exit
else
    echo "bad" > bad.txt
    exit
fi

the “test -s” tests if the file exists and is non-zero in size :slight_smile:

Cheers buddy, the find thing was along the lines of nul vaules when looking in the txt file :slight_smile:
will test this out now :slight_smile:

you could always try

cat version.txt | wc -l

counts the number of lines in the file then check if that is >0 :slight_smile:

or wc -l < version.txt if you want to be particularly terse :wink:

oh I do, I do :smiley: