Hi All,
I am looking for a awk/shell which can find an element named REFERENCE in a XML file and check whether it is empty or not.
If there is no value in the REFERENCE element then correspondingly move the file to some other folder.
The Unix server is AIX version 4.
Any inputs would be highly appreciated.
Thanks
Karan
Niroj
August 22, 2008, 2:57am
2
karansachdeva:
Hi All,
I am looking for a awk/shell which can find an element named REFERENCE in a XML file and check whether it is empty or not.
If there is no value in the REFERENCE element then correspondingly move the file to some other folder.
The Unix server is AIX version 4.
Any inputs would be highly appreciated.
Thanks
Karan
if [ `cat my.xml | grep "<REFERENCE>.*</<REFERENCE>" | wc -l` = 0 ]
> then
> mv my.xml dir_nm
> fi
Thanks fior the reply can you please let me know if i want to check a directory for all the files without reference element and then move them how can i do that.
I think the one you wrote will apply to one file only. I apologise i dont know Unix much so maybe might be wrong somewhere
for FILE in `ls -1 .xml`
do
if [ `cat $FILE| grep "<REFERENCE>. </<REFERENCE>" | wc -l` = 0 ]
then
mv $FILE dir_nm
fi
done
it is giving me all the files whether empty reference element or not...
the empty XML file could be like
<REFERENCE></REFERENCE>
<REFERENCE />
When i ran this script it moved all the files whether having a value or not in REFERENCE element.
Can you please assist me on this...
Hi this is the solution which i tried and is working...can someone pls look at it and let me know if it could cause some problem
for FILE in \`ls -1 *.xml\`
\+2 do
\+3 if [ \`cat $FILE| grep -F "<REFERENCE></REFERENCE>" | wc -l\` -gt 0 ]
\+4 then
\+5 \#mv $FILE /dfds03/editst6/guru
\+6 echo $FILE
\+7 elif [ \`cat $FILE| grep -F "<REFERENCE />" | wc -l\` -gt 0 ]
\+8 then
\+9 \#mv $FILE /dfds03/editst6/guru
+10 echo $FILE
+11 elif [ `cat $FILE| grep -F "<REFERENCE/>" | wc -l` -gt 0 ]
+12 then
+13 #mv $FILE /dfds03/editst6/guru
+14 echo $FILE
+15 fi
+16 done
Thanks & Regards
Karan
Niroj
August 22, 2008, 7:16am
7
echo "Enter dir name frm whr u wanna search:--give the full path--"
read dir
if [ ! -d "$dir" ]; then
echo "Dir not found!"
exit
fi
echo "Enter destination dir path:"
read destdir_nm
for FILE in `find $dir -name *.xml`
do
if [ -f $FILE ] && [ `cat $FILE | grep "<REFERENCE></REFERENCE>" | wc -l` -gt 0 ] || [ `cat $FILE | grep "<REFERENCE />" | wc -l` -gt 0 ]
then
echo "! File Found: $FILE "
mv $FILE $destdir_nm
fi
done
I got this below error while running this script...
Enter dir name frm whr u wanna search:--give the full path--
/dfds03/editst6/karan
Enter destination dir path:
/dfds03/editst6/guru
find: 0652-009 There is a missing conjunction
Can you tell what the issue is...
i think *.xml should be enclosed in double quotes
Niroj
September 10, 2008, 6:13am
10
It is working fine ..
I am using ksh..