Can you pleas help me with below requirement?
There is only one big line in the file. I need to parse block by block(particular tag values, 'Val' in below case) to get different parameters.
You could write a simple awk programme to extract the bits you need.
It makes a few assumptions about your code (and that you have GNU awk) which might be wrong, but it works on the small sample you posted and thus might work across all of your input.
Thanks a lot agama. Its working as I expected.
Could you please explain the code. I am newbie to Linux. So it would be very helpful for me if you kindly explain the code.
First, the very last line sets the record separator variable (RS) to be either the greater-than or less-than symbol. That splits all of the input file into records based on either of those rather than a newline. An important thing to note is that awk removes those symbols from the input as it uses them to split the input into records.
Awk processes records and the programme is applied to each record. for more details about awk, and the general syntax of an awk programme it is best to have a peek at this: Awk - A Tutorial and Introduction - by Bruce Barnett
Comments in-line below should explain things more...
So, for the first bits of your input (<?xml version="1.1" encoding="UTF-8"?> <Data> awk treats it as several records:
(Notice that the blanks between greater and less than symbols end up being blank records; not important, but interesting.) None of these records match our desired record, and they are discarded.
The first record that matches looks initially like:
After substitutions it becomes:
The split into 'a' using the greater than symbol as the separator yields these tokens in the array:
While your sample data didn't contain any spaces between the double quotes (e.g. Db="foo bar") the bracketing and splitting would have preserved them.
The tokens in the array 'a' can then be split, and placed into the hash 'h'. So a[8] is split into 'qry' and 'sdsds?q=dsds' and then can be referenced by name (e.g. h["qry"]).
Hope this helps you understand a bit more.
I also noticed this odd bit in your sample data: Te=" Ca="xxx" I'm not an XML expert, but this seems illegal syntax. I treated it as Te="".
Hi everyone,
So i'm struggling with an xml (log file) where we get information about some devices, so the logfile is filled with multiple "blocks" like that.
Based on the <devId> i want to extract this part of the xml file. If possible I want it to have an script for this, cause we'll use... (5 Replies)
I want to comment a block of code in xml. Note that the tags will be similar. In the below xml code, I want to block the listener block for com.pkg1.class2. How do i do it ?
Thanks in Advance
<listener>
<listener-class>com.pkg1.class1</listener-class>
</listener>
.........
<listener>... (4 Replies)
I want to process a file block by block using sed, and if that block does not contain two patterns, then that complete block has to be printed.
See below for the example data.
................................server 1...............................
running process 1
running... (8 Replies)
Hi All,
I need to umcomment an XML block (if it's not already uncommented) in a shell script. There are several commented blocks in the file that need to remain commented out. The challenging part for me is that I need to match a comment on one line and an XML tag on the following line. Also,... (0 Replies)
I tried searching the forums, but couldn't find anything relevant to my question.
I have an xml file like the following:
<topLevel numberBlock="BLOCK1">
<item="content1" title="Content 1">
<RefPath="path/to/file1.txt />
</item>
<item"content2" title="Content 2" >... (4 Replies)
hi,
i need my bash script to find regex in xml file.. and comment 2 lines before and after the line that contains regex.. can't use # needs to be <!-- at the beginning and --> and the end of the comment.
so eg..
first block
<filter>
<filter-name>MyRegEx</filter-name>
... (11 Replies)
Hi,
There's an xml file produced from a front-end tool as shown below:
<INPUT DATABASE ="ORACLE" DBNAME ="UNIX" NAME ="FACT_TABLE" OWNERNAME ="DIPS">
<INPUTFIELD DATATYPE ="double" DEFAULTVALUE ="" DESCRIPTION ="" NAME ="STORE_KEY" PICTURETEXT ="" PORTTYPE ="INPUT" PRECISION ="15" SCALE... (6 Replies)
Hi
I am new to this forum.
I have few XML files and from each xml file I want to copy some specific 50 no of lines and copy them to some other file.
how to do that? pls help.. (5 Replies)