Hi Unix Gurus,
I have some 145+ xml in some folder and I want just loadOperation to be printed. Sample o/p:
file1.xml loadOperation="InsertOrUpdate">
file2.xml loadOperation="Update">
file3.xml loadOperation="Update">
file4.xml loadOperation="Append">
In some of them, in the 2nd line, last column is loadOperation; but in some of them last column is sourceTable. But in those cases, 2nd last column is always loadOperation. Sample given:
--Last column is NOT loadOperation
<DataMapping123 xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="DataMappping123.xsd" name="fileOperation_1_type" table="XYZ" loadOperation="Stage" sourceTable="ABC">
--Last column is loadOperation
<DataMapping533 xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="DataMappping533.xsd" name="fileOperation_15_type" table="XYZ" loadOperation="Append">
So I tried the below:
1st with direct $NF print, not getting desired output though:
head -2 fileName2.xml|tail -1 |awk '{print $NF}'
2nd with conditional statement, still not printing the desired column ( I guess I'm not able to do partial match):
$ head -2 fileName1.xml|tail -1 |awk -v col=loadOperation '{if ($NF==col) {print $NF} else {print $(NF-1)}}'
my final code will be with for
command as below:
for logTime in `ls *.xml`; do logTailString=`head -2 $logTime|tail -1 |<<here goes the proper awk script>>; echo "$1 $logTime $logTailString"; done
Any type of suggestions welcome. I'm open for ideas.
Cheers,
Sapy.