I once wrote a generic XML scanner which produces output similar to what you want. It produces columns from tags in a generic way without hardcoding tags/attributes. It has a weakness in that it can't handle spaces inside tag attributes.
Getting those two 'env' tags into one can be done with sed.
Code:
$ cat xmlg.awk
BEGIN { RS="<"; FS=">"; ORS="\r\n";
# Change this to alter how many close-tags in a row are needed
# before a row of data is printed.
DEP=1
SEP="\t"
}
# Skip weird XML specification lines or blank records
/^\?/ || /^$/ { next }
# Handle close tags
/^[/]/ {
N=D; while((N>0) && ("/"STACK[N] != $1)) N--;
if("/"STACK[N] == $1) D=(N-1);
POP++;
if(POP == DEP)
{
if(!HEADER++)
{
split(ARG[1], Z, SUBSEP);
printf("%s %s", Z[2], Z[3]);
for(N=2; N<=ARG_; N++)
{
split(ARG[N], Z, SUBSEP);
printf("%s%s %s", SEP, Z[2], Z[3]);
}
printf("\n");
}
printf("%s", DATA[ARG[1]]);
for(N=2; N<=ARG_; N++)
printf("%s%s", SEP, DATA[ARG[N]]);
printf("\n");
}
next
}
# Handle open tags
{
gsub(/^[ \r\n\t]*/, "", $2); # Whitespace isn't data
gsub(/[ \r\n\t]*$/, "", $2);
sub(/\/$/, "", $(NF-1));
# Reset parameters
POP=0;
M=split($1, A, " ");
STACK[++D]=A[1];
if((!MAX) || (D>MAX)) MAX=D; # Save max depth
# Handle parameters
Q=split(A[2], B, " ");
for(N=1; N<=Q; N++)
{
split(B[N], C, "=");
gsub(/['"]/,"", C[2]);
I=D SUBSEP STACK[D] SUBSEP C[1];
if(!SEEN[I]++)
ARG[++ARG_]=I;
DATA[I]=C[2];
}
if($2)
{
I=D SUBSEP STACK[D] SUBSEP "CDATA";
if(!SEEN[I]++)
ARG[++ARG_]=I;
DATA[I]=$2;
}
}
$ sed 's/env="\([^"]*\)" env="\([^"]*\)"/env="\1\2"/g' 3.xml | awk -f xmlg.awk
rel ver mod name node env ins ip ins ip
123 on ac1 10.192.0.1 10.192.0.2
123 on ac2 10.192.0.3 10.192.0.4
123 on pr 10.192.0.5 10.192.0.6
123 off ac1 10.192.0.7 10.192.0.6
123 off ac2 10.192.0.8 10.192.0.6
123 off pr 10.192.0.9 10.192.0.6
$
Hi All,
I am new to Shell scripting.
I have a log file containing XML Messages.Each XML Message is accompanied with a timestamp.I need to count the the number of messages that get logged in a particular timeinterval.Is there any command/Syntax to achieve this.
Any code/example is... (5 Replies)
Hi all
Is there a way in awk to know that you are processing your final line of input if you do no know how many lines were in the input to begin with?
Thanks (7 Replies)
Hi,
i am really fresh with shell scripting and programming,
i have an issue i am not able to solve to populate data on my server for Cisco IP phones.
I have CSV file within the following format:
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;... (9 Replies)
Hello,
I trying to extract text that is surrounded by xml-tags. I tried this
cat tst.xml | egrep "<SERVER>.*</SERVER>" |sed -e "s/<SERVER>\(.*\)<\/SERVER>/\1/"|tr "|" " "
which works perfect, if the start-tag and the end-tag are in the same line, e.g.:
<tag1>Hello Linux-Users</tag1>
... (5 Replies)
Hi everyone,
I have Xml files in a folder, I need to extract some attribute values form xml files and store in a hash. My xml file look like this.
<?xml version="1.0" encoding="UTF-8"?>
<Servicelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"... (0 Replies)
I need to get all session_ID 's for product="D-0002" from a XML file:
Sample input:
<session session_ID="6411206" create_date="2012-04-10-10.22.13.000000">
<marketing_info>
<program_id>D4AWFU</program_id>
<subchannel_id>abc</subchannel_id>
</marketing_info>
... (1 Reply)
Hello,
I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this :
This is the output of ls command : I stored the output in a file filelist
1.1M... (5 Replies)
Hi ,
I have a below xml:
<ns:Body>
<ns:result>
<Date Month="June" Day="Monday:/>
</ns:result>
</ns:Body>
i have a lookup abc.txtt text file with below details
Month June July August
Day Monday Tuesday Wednesday
I need a output xml with below tags
<ns:Body>
<ns:result>... (2 Replies)
I've been kicking this around for a while now, I might as well post it here.
v0.0.9, now properly supporting self-closing tags.
v0.0.8, an important quoting fix and a minor change which should handle special <? <!-- etc. tags without seizing up as often. Otherwise the code hasn't changed much.... (6 Replies)
Discussion started by: Corona688
6 Replies
LEARN ABOUT MINIX
ctags
CTAGS(1) General Commands Manual CTAGS(1)NAME
ctags - Generates "tags" and (optionally) "refs" files
SYNOPSIS
ctags [-stvra] filesnames...
DESCRIPTION
ctags generates the "tags" and "refs" files from a group of C source files. The "tags" file is used by Elvis' ":tag" command, control-]
command, and -t option. The "refs" file is sometimes used by the ref(1) program.
Each C source file is scanned for #define statements and global function definitions. The name of the macro or function becomes the name
of a tag. For each tag, a line is added to the "tags" file which contains:
- the name of the tag
- a tab character
- the name of the file containing the tag
- a tab character
- a way to find the particular line within the file.
The filenames list will typically be the names of all C source files in the current directory, like this:
$ ctags -stv *.[ch]
OPTIONS -t Include typedefs. A tag will be generated for each user-defined type. Also tags will be generated for struct and enum names.
Types are considered to be global if they are defined in a header file, and static if they are defined in a C source file.
-v Include variable declarations. A tag will be generated for each variable, except for those that are declared inside the body of a
function.
-s Include static tags. Ctags will normally put global tags in the "tags" file, and silently ignore the static tags. This flag causes
both global and static tags to be added. The name of a static tag is generated by prefixing the name of the declared item with the
name of the file where it is defined, with a colon in between. For example, "static foo(){}" in "bar.c" results in a tag named
"bar.c:foo".
-r This causes ctags to generate both "tags" and "refs". Without -r, it would only generate "tags".
-a Append to "tags", and maybe "refs". Normally, ctags overwrites these files each time it is invoked. This flag is useful when you
have to many files in the current directory for you to list them on a single command-line; it allows you to split the arguments
among several invocations.
FILES
tags A cross-reference that lists each tag name, the name of the source file that contains it, and a way to locate a particular line in
the source file.
refs The "refs" file contains the definitions for each tag in the "tags" file, and very little else. This file can be useful, for exam-
ple, when licensing restrictions prevent you from making the source code to the standard C library readable by everybody, but you
still everybody to know what arguments the library functions need.
BUGS
ctags is sensitive to indenting and line breaks. Consequently, it might not discover all of the tags in a file that is formatted in an
unusual way.
SEE ALSO elvis(1), refs(1)AUTHOR
Steve Kirkendall
kirkenda@cs.pdx.edu
CTAGS(1)