regex - Shell script to extract certain fields from XML files -
I'm new to Linux open and I'm not able to understand regex.
Here's my question: I have a directory named / var / visitors
and under this directory, I have a
, b
, c
,
d
. In each of these directories, there is a file named list.xml
and here, for example, list.xml
to / var / visitors / a
:
& lt; Key & gt; Name & lt; / Key & gt; & Lt; String & gt; Mr. Jones & lt; / String & gt; & Lt; Key & gt; Id & lt; / Key & gt; & Lt; String & gt; 51 & lt; / String & gt; & Lt; Key & gt; Lane & lt; / Key & gt; & Lt; String & gt; 53151334 & lt; / String & gt;
I have to merge the name
field with its corresponding string and merge the id
field with its associated string. I do not need any other fields.
Name: Mr. Jones ID: 51 --- Name: MS Maggi Id: 502
Here's how far I got:
< Find pre> cd / var / visitor-name "list.xml" | Xerose grapes
Please help.
is not elegant, but it will work:
Name "list.xml" | X-cat | Tr-d "\ n" | Sed's / & lt; \ / String> / \ N / g '| | Sed's / & lt; \ / Key> /: / G '| | Sed's / & lt; [^ & Gt;] * & gt; //g '| | Like "name: | id:" | In fact it does this: - Delete all new lines < / Li>
-
- Remove all element content (between & lt; and>)
- Save only names and id fields (drop all other) < Li> Add --- Separator
Sample output:
--- Name: Greg ID: 52 --- Name: Amy ID: 53 - - Name: Mr. Jones ID: 51
Comments
Post a Comment