![]() |
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 |
| Scripting change of text in another file | vwgtiturbo | Shell Programming and Scripting | 7 | 08-31-2009 10:47 PM |
| Search text from a file and print text and one previous line too | kamranjalal | Shell Programming and Scripting | 6 | 01-06-2009 03:27 AM |
| search and replace a specific text in text file? | santosham | UNIX for Dummies Questions & Answers | 4 | 06-25-2008 05:53 PM |
| Building Full-Text Search Applications with Oracle Text | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 05:10 AM |
| Perl: Search for string on line then search and replace text | Crypto | Shell Programming and Scripting | 4 | 01-04-2008 10:24 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
UNIX Text Search Scripting
Hi,
I'm trying to extract XML values for a particular field (MessageId) from a file that has multiple XML data on many lines. For example: Line1: <?xml version = "1.0"?><xml></xml><xml></xml><xml></xml><xml></xml><xml></xml><field name='MessageId'><value>123456789</value></field><xml></xml><xml></xml><xml></xml><xml></xml> Line2:<?xml version = "1.0"?><xml></xml><xml></xml><xml></xml><field name='MessageId'><value>987654321</value></field><xml></xml><xml></xml><xml></xml> . . Line n Please note: MessageId does not appear in the same position from line to line. The red text is the same format for each line. I haven't been able to find anything on the forums for my situation. Everything I've tried with sed has been returning the whole line as opposed to just the string of numbers for MessageId. My goal is to store them in an array so I can do searches on another data file. Any help would be greatly appreciated! Thanks, Matt |
|
||||
|
are you expecting this ?!
Code:
grep -o "<field name='MessageId'>.*</field>" t1 <field name='MessageId'><value>123456789</value></field> <field name='MessageId'><value>987654321</value></field> |
|
||||
|
It certainly is not standard.
The man page says "show only the part of the line that matches PATTERN"? That's what SED is for! I was at least hoping that the -o option wasn't greedy, but it still grabs what it can. Is there a UUOO (useless use of options award)? |
![]() |
| Bookmarks |
| Tags |
| shell script, xml |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|