![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |