The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading an Input file and searching for occurrences WIHOUT SED or AWK kartikkumar84@g Shell Programming and Scripting 2 05-08-2008 05:16 PM
Searching filenames containing certain text??? skyineyes UNIX for Advanced & Expert Users 6 01-16-2008 04:48 AM
reading and searching xml element text in script forevercalz Shell Programming and Scripting 6 11-10-2005 08:35 PM
Help with searching a text file thekid2 Shell Programming and Scripting 6 01-01-2004 11:09 PM
Reading from files and searching them Prometheus20 Shell Programming and Scripting 1 05-02-2002 09:52 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-24-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
Post reading and searching xml element text in script

well i have this xml file here: this file is called filereader.xml
<?xml version="1.0" encoding="UTF-8"?>
<file>
<file1>
<filecopy>/new/test/thefile.txt</filecopy>
<filecopy>/new/test/thefile2.ppt</filecopy>

</file1>
</file>

i need to write the script that search for the Bold text inside the xml without using java. The underlined part is the directory... so the script will first look into the tag--filecopy..then look into a basedirectory which i created called checkdirectory after that it will look into /new/test/ in the tag which is also a directory to locate the file.

Eg. thefile.txt is in checkdir/new/test/thefile.txt
and thefile2 is in checkdir/new/thefile2.txt

i have a code here....but it will only capture file in the tag...it will not look into /new/test folder...can someone help me out?

the coding i have is :
#!/bin/sh

sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml | while read file; do
if [ -f "../checkdir/${file}" ]; then
echo "File exists : ${file}"
else
echo "File not exist : $${file}"
fi
done

exit 0

Last edited by forevercalz; 11-24-2005 at 06:37 PM.
Reply With Quote
Forum Sponsor
  #2  
Old 11-24-2005
Registered User
 

Join Date: Sep 2005
Posts: 45
Where are you running the script from? I can't see anything wrong with it as it stands.

Is that supposed to be two full-stops in the file-test? If you're running it from the directory containing checkdir, then it should be one.

Cheers
Reply With Quote
  #3  
Old 11-24-2005
Registered User
 

Join Date: Sep 2005
Posts: 74
Well..i manage to solve the problems now...
by doing this

sed -e '/filecopy/ !d' -e 's!<filecopy>\([^<]*\)</filecopy>!\1!' filereader.xml | while read file; do
file_dir=$checkdir/${file}
if [ -f "$file_dir" ]; then
echo "File exists : $file_dir"
else
echo "File not exist : $file_dir"
fi
done

Last edited by forevercalz; 11-24-2005 at 07:12 PM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0