![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read each word from File1 and search each file in file2 | clem2610 | Shell Programming and Scripting | 8 | 04-23-2009 09:13 AM |
| search a word from file | vishy | Shell Programming and Scripting | 9 | 02-08-2008 05:15 PM |
| search file for word, then assign to variable | dejit | UNIX for Dummies Questions & Answers | 2 | 03-06-2007 01:57 PM |
| Finding word in file then print the preceding.... | g_jumpin | Shell Programming and Scripting | 5 | 10-05-2006 11:31 AM |
| Print out just a word from the file | Kinki | Shell Programming and Scripting | 8 | 02-20-2005 11:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
search a word in a xml file and print the out put
hi ,
i m having a html file and this file looks like this Code:
<ssl>
<name>PIA</name>
<enabled>true</enabled>
<listen-port>39370</listen-port>
</ssl>
<log>
<name>PIA</name>
</log>
<execute-queue>
<name>weblogic.kernel.Default</name>
<thread-count>50</thread-count>
</execute-queue>
<listen-port>37390</listen-port>
thanks in advance with regards , ram Last edited by Yogesh Sawant; 07-01-2009 at 04:32 AM.. Reason: added code tags |
|
||||
|
you can try something like this:
Code:
awk 'BEGIN { FS=" "; OFS=" " }
{
if ( $0 ~ /<listen-port>/ && $0 ~ /<\/listen-port>/ ){
# <listen-port>39370</listen-port>
split($0,A,"\\076")
# 39370</listen-port>
split(A[2],LP,"\\074")
listen_port=LP[1]
printf("listen port is %s\n",listen_port)
}
}
END {
}' xmlfile
|
|
||||
|
even below may help you some. But if it is well-formatted XML, suggest you t o use XML parser in Perl to handler this kind of issue.
Code:
sed -n '/<listen-port>/{s/<listen-port>\(.*\)<\/listen-port>/\1/;p;}' yourfile
|
|
||||
|
Try this in perl!
You can try this in perl!
Code:
#!/usr/local/bin/perl
open( INPUT_FILE, "$ARGV[0]" ) || die "Cannot open input file $ARGV[0]\n";
while ($line = <INPUT_FILE>)
{
chop $line;
@base=split(/\>/,$line);
$base[0] =~ s/[\<]*//;
$LengthOfTag=length($base[0]);
$TotalLength=length($line);
$FinalLength=$TotalLength - $LengthOfTag - $LengthOfTag - 5;
$val=substr($line,$LengthOfTag+2,$FinalLength);
if ( $base[0] eq "listen-port" )
{
print "$val\n";
}
}
close(INPUT_FILE);
Last edited by Yogesh Sawant; 07-01-2009 at 04:31 AM.. Reason: added code tags |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|