0

I have two files

Content of file A

paybackFile_537214-760887_000_20120801.xml
paybackFile_354472-544899_000_20120801.xml
paybackFile_62-11033_000_20120801.xml
paybackFile_831669-837544_000_20120801.xml
===========================================
Total file(s) - 4
===========================================

Content of file B

14/08/2012 12:36:01: MSG: File paybackFile_537214-760887_000_20120801.xml.gpg decrypted successfully.
13/08/2012 11:36:01: MSG: File paybackFile_62-11033_000_20120801.xml.gpg not decrypted successfully.

Here i have names of .xml files. From file A we check that **.xml file is present in file B and also check whether it has been decrypted successfully.

Could you please help me with this.

Thanks in advance.

Regards, Smita

1
  • Here in fileA i have 100 records and in fileB i have 80 records. From fileA i have to take the name of file which is ***.xml(from a string given above) then have to verify whether that ***.xml file(which is also a part of string) is present in fileB. We also need to verify whether in fileB if ***.xml is present,then its decrypted successfully or not. Commented Sep 4, 2012 at 9:47

3 Answers 3

1
awk 'FNR==NR{a[$2".gpg"];next}(($5 in a) && ($0~/decrypted/))' filea fileb
Sign up to request clarification or add additional context in comments.

2 Comments

When using command awk 'FNR==NR{a[$2".gpg"];next}(($5 in a) && ($0~/decrypted/))' filea fileb > fileC there is no data in fileC. fileC should have paybackFile_521000-845442_000_20120701.xml missing
The scenario is.. if file successfully found and decrypted then echo success else print the missing or not decrypted in fileC
0

Create a script named compare.awk. Paste this inside:

FILENAME=="fileB" && $5 ~ /xml/ {
     if ($6 == "decrypted" && $7 == "successfully.") {
         decrypted_file[$5] = 1;
     } else {
         decrypted_file[$5] = 2;
     }
}
FILENAME=="fileA" && $2 ~ /xml/ {
    if (decrypted_file[$2".gpg"] == 1) {
        print $2" exist and decrypted";
    } else if (decrypted_file[$2".gpg"] == 2) {
        print $2" exist but not decrypted";
    } else {
        print $2" not exist in fileB";
    }
}

Call it by:

awk -F' ' -f compare.awk fileB fileA

[EDIT] For shell without awk script, (still need grep, sed, cut and wc tho):

#!/bin/bash

TESTA=`grep ".xml" fileA | cut -d' ' -f2`
TESTB=`grep ".xml" fileB | cut -d' ' -f5,6,7 | sed 's/ /-/g'`
DECRYPT_YES=""
DECRYPT_NO=""

for B in ${TESTB}
do
 DECRYPT_B=`echo ${B} | sed 's/.*gpg-decrypted-successfully\./1/'`
 if [ ${DECRYPT_B} == "1" ]
 then
   DECRYPT_YES=${DECRYPT_YES}" "`echo ${B} | sed 's/\.gpg.*//g'`
 else
   DECRYPT_NO=${DECRYPT_NO}" "`echo ${B} | sed 's/\.gpg.*//g'`
 fi
done

for FILE_A in ${TESTA}
do
 if [ `echo ${DECRYPT_YES} | grep "${FILE_A}" | wc -l` == 1 ]
 then
  echo ${FILE_A}" exist and decrypted"
 elif [ `echo ${DECRYPT_NO} | grep "${FILE_A}" | wc -l` == 1 ]
 then
  echo ${FILE_A}" exist but not decrypted"
 else
  echo ${FILE_A}" not exist"
 fi
done

5 Comments

Here in fileA i have 100 records and in fileB i have 80 records. From fileA i have to take the name of file which is ***.xml(from a string given above) then have to verify whether that ***.xml file(which is also a part of string) is present in fileB. We also need to verify whether in fileB if ***.xml is present,then its decrypted successfully or not.
there, updated the compare.awk script. Hopefully that's what you expected to get.
Hello Andere, Thank you,the awk script works as expected. But cant this be done using shell script? As awk script is the second option. Regards, Smita
Well there's shell script, but still need sed, grep, cut and wc.
Hello, i need to have names of ***.xml files of the scenarios which are "exist but not decrypted" and "not exist" in a separate file. How can i add this feature to the above existing code?
0

Here's a script:

#!/bin/sh

FILEA=fileA
FILEB=fileB

awk -F" " ' { print $2 } ' $FILEA > .tmpfileA 
awk -F" " ' { print $5 } ' $FILEB | sed 's/\.gpg//' | grep 'decrypted successfully' > .tmpfileB


diff .tmpfileA .tmpfileB

rm -f .tmpfileA
rm -f .tmpfileB

All you'll need to change is the variables FILEA and FILEB

When executing it with the inputs you provided it gives the following result:

$ testAB.ksh 
2d1
< paybackFile_521000-845442_000_20120701.xml
$ 

3 Comments

The above script only compares whether ***.xml file present in fileB. It does not checks whether the ***.xml file is successfully decrypted or not.
all you need is to grep 'decrypted successfully' in the second file. I updated the answer.
It just gives the names of words at second location, it doesn't even compares the data. Also there is little change in the requirement, please look at it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.