How do I extract parameter value after name="value" accurately?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do I extract parameter value after name="value" accurately?
# 1  
Old 02-12-2016
How do I extract parameter value after name="value" accurately?

How do I extract initialHeapSize and maximumHeapSize values accurately?
Code:
        <jvmEntries xmi:id="JavaVirtualMachine_1337159909831" verboseModeClass="false" verboseModeGarbageCollection="true" verboseModeJNI="false" initialHeapSize="256" maximumHeapSize="512" runHProf="false" hprofArguments="" debugMode="false" debugArgs="-Djava.compiler=NONE -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7777" enericJvmArguments="-Dawt.headless=true -Xjit:disableIdiomRecognition -Dsun.net.inetaddr.ttl=120">

I want the code to handle potential variations to input.
Code:
1. initialHeapSize=256 maximumHeapSize=512
2. initialHeapSize='256' maximumHeapSize='512'
3. initialHeapSize = 256 maximumHeapSize = 512
etc..

Done right this is very useful to extract parameter values from config files or
ps -ef etc output.

I have a working version that using awk and cut,, but it can't handle any of the potential variations to value format mentioned above.

Last edited by kchinnam; 02-12-2016 at 11:06 PM..
# 2  
Old 02-12-2016
Show us your working shell script using awk and cut and maybe we can help you extend its capabilities.

What operating system and shell are you using?
# 3  
Old 02-12-2016
Here is the bash and Linux version:
Code:
GNU bash, version 3.2.51(1)-release (x86_64-suse-linux-gnu)


This is working,, but I am concerned that it can go wrong in many ways.
Code:
        MIN_HEAP=`cat server.xml | grep -i "<jvmEntries" | sed -e 's/"/ /g' | awk '{print $11}'`
        MAX_HEAP=`cat server.xml | grep -i "<jvmEntries" | sed -e 's/"/ /g' | awk '{print $13}'`

# 4  
Old 02-12-2016
In the first post in this thread, you showed three lines from an XML file containing a single <jvmEntries> tag with its options. But, the code you showed us in the third post in this thread only works if that entire tag is contained on a single line (not on three lines). Is that tag on three lines or on one line?

Will the strings initialHeapSize and maximumHeapSize immediately followed by zero or more spaces immediately followed by an equal sign ever appear in your XML file outside of the <jvmEntries> tag?

You are performing a case-insensitive search for the tag jvmEntries, do we also need to search for initialHeapSize and maximumHeapSize without regard to case, or are those strings always presented exactly as shown?
# 5  
Old 02-12-2016
my input is in a XML and <jvmEntries> is in a single line.
initialHeapSize and maximumHeapSize appear only once in the XML file inside <jvmEntries> tag.
case insensitive search is to make it more robust. At present input has name="value" format without spaces. But as I explained input can change and still be valid,, how can script be more smarter?

if you are aware of any java run-time arguments used to start application processes, they have min, max heap size parameters visible in ps -auxww output. ability to get parameter values with some tolerance would help a great deal.
# 6  
Old 02-12-2016
The following produces the same result that you posted for MIN_HEAP and MAX_HEAP

Code:
MIN_HEAP=$(perl -ne 'print /initialHeapSize[ \x27"=]+(\d+)/' server.xml)

Code:
echo $MIN_HEAP
256

Code:
MAX_HEAP=$(perl -ne 'print /maximumHeapSize[ \x27"=]+(\d+)/' server.xml)

Code:
echo $MAX_HEAP
512

That accommodates for any of the followings:
Code:
(initial|maximum)HeapSize '512'
(initial|maximum)HeapSize 512
(initial|maximum)HeapSize='512'
(initial|maximum)HeapSize = '512'
(initial|maximum)HeapSize = "512'
(initial|maximum)HeapSize = "512"
(initial|maximum)HeapSize = '512"
(initial|maximum)HeapSize= "512"
(initial|maximum)HeapSize ="512"
Or any variation with single quotes.


Last edited by Aia; 02-12-2016 at 11:34 PM.. Reason: Correct MAX_HEAP
This User Gave Thanks to Aia For This Post:
# 7  
Old 02-13-2016
Aia perl solution is working great. Thanks.
I would like to know how this can be done using sed -e or
GNU grep -P -o which are more native to bash.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Beginners Questions & Answers

Extract delta records using with "comm" and "sort" commands combination

Hi All, I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file. comm -3 < sort file_old < sort file_new > new_file I am getting the below error: -ksh: sort: cannot open But if I do... (7 Replies)
Discussion started by: njny
7 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. UNIX for Dummies Questions & Answers

Shc script size limitation and "_SC_ARG_MAX (see sysconf(2))" parameter

I wish to change the parameter (which I do not understand exactly what it is and I wish to) and be able to use shc with very long bash scripts (2 Replies)
Discussion started by: frad
2 Replies

6. Shell Programming and Scripting

Help with error "por: 0403-012 A test command parameter is not valid."

Hi, im asking for help with the next script: echo ^; then if then printf "\033 query1.sh: export TERM=vt100 export ORACLE_TERM=at386 export ORACLE_HOME=/home_oracle8i/app/oracle/product/8.1.7 export ORACLE_BASE=/home_oracle8i/app/oracle export... (8 Replies)
Discussion started by: blacksteel1988
8 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Dummies Questions & Answers

What is meant by Kernel Parameter "dflssiz" in Digital Unix (OSF)

Hi, We have a Digital Unix Server with OSF. There's a Kernel Parameter "dflssiz" on this server. I just want to know, what it means. Thanks (2 Replies)
Discussion started by: sameerdes
2 Replies
Login or Register to Ask a Question