Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on creating XML output in bash script 2

Status
Not open for further replies.

AlexCuse

Programmer
Apr 13, 2006
5,416
US
Hi all, don't get over to this neck of the woods much!

Let me preface my post by saying I have absolutely zero experience with UNIX.

However, I need to use this tool: ckjm to analyze some jar files, and it seems to be the only way to do it (I can get it to work with class files from DOS but not jar's).

So, I'm using a tool called cygwin, and it is processing the jar's successfully. BUT, the shell does not hold enough lines to capture all the output, so I am trying the script found on that site to output to XML. Here it is, for easy reference:

Code:
#!/bin/sed -f
1i\
<?xml version="1.0" ?>\
<ckjm>
s/^/<metric><classname>/
s/ /<\/classname><WMC>/
s/ /<\/WMC><DIT>/
s/ /<\/DIT><NOC>/
s/ /<\/NOC><CBO>/
s/ /<\/CBO><RFC>/
s/ /<\/RFC><LCOM>/
s/ /<\/LCOM><Ca>/
s/ /<\/Ca><NPM>/
s/$/<\/NPM><\/metric>/
$a\
</ckjm>

Here is how I am using it:

Code:
$ jar tf lib/derby.jar | c:/db-derby-10.1.1.0-bin/ckjm2xml.bash >derby.xml | java -jar ckjm-1.8.jar

The output is only showing the classname attribute, and omitting all the tags up until </NPM>

Here is an example:

Code:
<metric><classname>org/apache/derby/impl/sql/catalog/TDCacheable.class</NPM></metric>
<metric><classname>org/apache/derby/impl/sql/catalog/TabInfoImpl.class</NPM></metric>
<metric><classname>org/apache/derby/impl/sql/catalog/TableKey.class</NPM></metric>

I am sure this is just some syntax problem, but with this being so foreign to me, I don't know where to begin to look (except for tek-tips ;-) )

I would appreciate any guidance anyone has in getting this to work.

Thanks in advance,

Alex



[small]----signature below----[/small]
You can't fit a square data in a round table
 
I suppose I should add that the data I need to write is a space-separated line containing a class name and measurements for 8 metrics.

output looks like this:

Code:
org/apache/myclass.class 0 1 3 4 9 2 0 1

Thanks again,

Alex

[small]----signature below----[/small]
You can't fit a square data in a round table
 
It looks like sed is ignoring all the requests to replace spaces. Some seds accept the [[:space:]] class so try
Code:
#!/bin/sed -f
1i\
<?xml version="1.0" ?>\
<ckjm>
s/^/<metric><classname>/
s/[[:space:]]/<\/classname><WMC>/
s/[[:space:]]/<\/WMC><DIT>/
s/[[:space:]]/<\/DIT><NOC>/
s/[[:space:]]/<\/NOC><CBO>/
s/[[:space:]]/<\/CBO><RFC>/
s/[[:space:]]/<\/RFC><LCOM>/
s/[[:space:]]/<\/LCOM><Ca>/
s/[[:space:]]/<\/Ca><NPM>/
s/$/<\/NPM><\/metric>/
$a\
</ckjm>

Ceci n'est pas une signature
Columb Healy
 
Seems that the input to sed have NO space in it ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks for the info fellas.

PHV - its' come to my attention that I am calling the ckjm2xml.bash script in the wrong sequence (s/b at the end), so that would fit with the input having no spaces.

Columb - that is good to know as well!

I just ordered a book on this stuff, as working on this has really exposed an area where I could use some improvement. I may be dropping in now and then as I try to work my way through the basics.

[cheers]

Alex

[small]----signature below----[/small]
You can't fit a square data in a round table

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top