|
|
Help processing an xml line
HI all,
I've been trying to solve this problem for a few hours and the best I
can come up with is this:
$ echo $line
<HOME NAME="Ora11g_gridinfrahome1" LOC="/cs/GRID/11.2" TYPE="O"
IDX="1" CRS="true">
$ echo $line | awk 'BEGIN { FS = "[\"|\"]" } { print $4 }'
/cs/GRID/11.2
Is there a nicer way to grab that value of LOC?
Thanks in advance.
Stu
|
|
0
|
|
|
|
Reply
|
Stuart
|
3/11/2010 11:22:23 AM |
|
Stuart à écrit :
> HI all,
>
> I've been trying to solve this problem for a few hours and the best I
> can come up with is this:
>
> $ echo $line
> <HOME NAME="Ora11g_gridinfrahome1" LOC="/cs/GRID/11.2" TYPE="O" IDX="1"
> CRS="true">
>
> $ echo $line | awk 'BEGIN { FS = "[\"|\"]" } { print $4 }'
> /cs/GRID/11.2
>
> Is there a nicer way to grab that value of LOC?
Not nicer, but LOC can be anywhere:
awk 'BEGIN { FS="LOC=\"" } split($2, a, "\""){ print a[1] }'
|
|
0
|
|
|
|
Reply
|
Laurianne
|
3/11/2010 1:50:45 PM
|
|
Stuart wrote:
> HI all,
>
> I've been trying to solve this problem for a few hours and the best I
> can come up with is this:
>
> $ echo $line
> <HOME NAME="Ora11g_gridinfrahome1" LOC="/cs/GRID/11.2" TYPE="O"
> IDX="1" CRS="true">
>
> $ echo $line | awk 'BEGIN { FS = "[\"|\"]" } { print $4 }'
> /cs/GRID/11.2
>
> Is there a nicer way to grab that value of LOC?
If you do a lot with XML you may want to have a look at xgawk (GNU awk
with XML support). It provides nice ways to access tags and attributes
beyond the primitive pattern matching approach.
Janis
>
> Thanks in advance.
>
> Stu
|
|
0
|
|
|
|
Reply
|
Janis
|
3/11/2010 5:31:21 PM
|
|
On 11 Mar, 18:31, Janis Papanagnou <janis_papanag...@hotmail.com>
wrote:
> Stuart wrote:
> > HI all,
>
> > I've been trying to solve this problem for a few hours and the best I
> > can come up with is this:
>
> > $ echo $line
> > <HOME NAME="Ora11g_gridinfrahome1" LOC="/cs/GRID/11.2" TYPE="O"
> > IDX="1" CRS="true">
>
> > $ echo $line | awk 'BEGIN { FS = "[\"|\"]" } { print $4 }'
> > /cs/GRID/11.2
>
> > Is there a nicer way to grab that value of LOC?
>
> If you do a lot with XML you may want to have a look at xgawk (GNU awk
> with XML support). It provides nice ways to access tags and attributes
> beyond the primitive pattern matching approach.
>
> Janis
>
>
>
>
>
> > Thanks in advance.
>
> > Stu- Hide quoted text -
>
> - Show quoted text -
Thanks to you both. This is just I one off. Thanks for your solution
Laurianne, this is what I was trying to get to, to remove the print
$4. Thanks.
|
|
0
|
|
|
|
Reply
|
Stuart
|
3/12/2010 8:44:37 AM
|
|
On 3/12/2010 2:44 AM, Stuart wrote:
> On 11 Mar, 18:31, Janis Papanagnou<janis_papanag...@hotmail.com>
> wrote:
>> Stuart wrote:
>>> HI all,
>>
>>> I've been trying to solve this problem for a few hours and the best I
>>> can come up with is this:
>>
>>> $ echo $line
>>> <HOME NAME="Ora11g_gridinfrahome1" LOC="/cs/GRID/11.2" TYPE="O"
>>> IDX="1" CRS="true">
>>
>>> $ echo $line | awk 'BEGIN { FS = "[\"|\"]" } { print $4 }'
>>> /cs/GRID/11.2
>>
>>> Is there a nicer way to grab that value of LOC?
>>
>> If you do a lot with XML you may want to have a look at xgawk (GNU awk
>> with XML support). It provides nice ways to access tags and attributes
>> beyond the primitive pattern matching approach.
>>
>> Janis
>>
>>
>>
>>
>>
>>> Thanks in advance.
>>
>>> Stu- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks to you both. This is just I one off. Thanks for your solution
> Laurianne, this is what I was trying to get to, to remove the print
> $4. Thanks.
Just watch out for input files like:
<FOO="abc" ENBLOC="bar" LOC="/cs/GRID/11.2" TYPE="O">
or other patterns like ENBLOC=" that could contain LOC=". If that could happen
you need a different solution.
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
3/12/2010 12:29:05 PM
|
|
Ed Morton wrote:
>> Thanks to you both. This is just I one off. Thanks for your solution
>> Laurianne, this is what I was trying to get to, to remove the print
>> $4. Thanks.
>
> Just watch out for input files like:
>
> <FOO="abc" ENBLOC="bar" LOC="/cs/GRID/11.2" TYPE="O">
>
> or other patterns like ENBLOC=" that could contain LOC=". If that could
> happen you need a different solution.
With gawk it should be possible to use \< and \y to match beginning of words
so FS="\\<LOC=\"" or FS="\\yLOC=\"" should do it with gawk.
|
|
0
|
|
|
|
Reply
|
pk
|
3/12/2010 12:54:55 PM
|
|
|
5 Replies
107 Views
(page loaded in 0.054 seconds)
|
|
|
|
|
|
|
|
|