<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Parsing a string in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123870#M802909</link>
    <description>Hi Rodney,&lt;BR /&gt;&lt;BR /&gt;The value of the big string I am obtaining is from running a process.&lt;BR /&gt;&lt;BR /&gt;I get that by &lt;BR /&gt;&lt;BR /&gt;s1= `echo  execprocess | grep..... etc`&lt;BR /&gt;&lt;BR /&gt;Then I was using this string against the expr. you gave.&lt;BR /&gt;&lt;BR /&gt; set -- `echo "$s1" | sed -e 's/[^(]*(\([0-9]*\))/ \1/g'`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It looks like this string contains lots of sp. chars and line breaks etc.&lt;BR /&gt;&lt;BR /&gt;My question is how can I make this string  a coherent one to fit into your expr.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;dude.</description>
    <pubDate>Wed, 19 Nov 2003 16:23:59 GMT</pubDate>
    <dc:creator>dude70</dc:creator>
    <dc:date>2003-11-19T16:23:59Z</dc:date>
    <item>
      <title>Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123859#M802898</link>
      <description>Hi I have a big sting like &lt;BR /&gt;&lt;BR /&gt;" Hi this is a big string  and i am trying to parse it this contains values v1(100) and v2(50)"&lt;BR /&gt;&lt;BR /&gt;I want to parse it using unix shell script to 2 strings like &lt;BR /&gt;val1=100 &lt;BR /&gt;val2=50 &lt;BR /&gt;can you pl. help me.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Wed, 19 Nov 2003 12:23:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123859#M802898</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-19T12:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123860#M802899</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;it should work with this:&lt;BR /&gt;val1=100&lt;BR /&gt;expr "Hi this is a big string and i am trying to parse it this contains values v&lt;BR /&gt;1(100) and v2(50)" : ".*\(${val1}\)"&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Nov 2003 12:55:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123860#M802899</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-11-19T12:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123861#M802900</link>
      <description>Hi Michael ,&lt;BR /&gt;&lt;BR /&gt;Thanks for the reply. It is actually a string s1 that i am getting in script from another operation. I want to extract the values 100 and 50 and assign it to another string s2 and s3 resp.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Wed, 19 Nov 2003 13:06:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123861#M802900</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-19T13:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123862#M802901</link>
      <description>Try this-&lt;BR /&gt; &lt;BR /&gt;set -- `echo "$x" | sed -e 's/[^(]*(\([0-9]*\))/ \1/g'`&lt;BR /&gt;val1=$1&lt;BR /&gt;val2=$2&lt;BR /&gt; &lt;BR /&gt;Where $x is your string.&lt;BR /&gt;sed command changes strings to " 100 50"&lt;BR /&gt;set -- will set command parameters from sed command.&lt;BR /&gt;Then $1 is first value, $2 is second&lt;BR /&gt; &lt;BR /&gt;HTH&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 19 Nov 2003 13:20:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123862#M802901</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-11-19T13:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123863#M802902</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt; Thanks for the reply. I won't work with that, because the string length may vary each time. The following is a sample only. Thing is v1 and v2 will be same. so I want to extract values from v1 and v2 and assign it to s2=100 and s3=50.&lt;BR /&gt;&lt;BR /&gt;s1 ="Hi this is a big string and i am trying to parse it this contains values v1(100) and v2(50) it goes on..."&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Nov 2003 13:34:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123863#M802902</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-19T13:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123864#M802903</link>
      <description>My solution doesn't matter on the size of the string or where the values are positioned. It will take the first number found in parenethis assign to val1 and take the second number found in parenthesis and assign to val2.&lt;BR /&gt; &lt;BR /&gt;It is based on relative position of the numbers within the string.&lt;BR /&gt; &lt;BR /&gt;Are you saying you want the text preceeding the number to be used to determine what variable name to be assigned (ie v1 goes to val1, v2 to val2)?&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 19 Nov 2003 13:51:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123864#M802903</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-11-19T13:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123865#M802904</link>
      <description>Hi Rodney,&lt;BR /&gt;&lt;BR /&gt;Thanks for the reply.&lt;BR /&gt;1. Actually it doesn't work that way. The expression you gave reads each string from the begining and assigns to $1..etc. I tested this. It does not read from the braces.&lt;BR /&gt;&lt;BR /&gt;2. yes like you said I want to take the value v1(100) and put that in a string s1 and v2(50) in s2. ie. s1=100 and s2=50. &lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Nov 2003 15:06:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123865#M802904</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-19T15:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123866#M802905</link>
      <description>give this a try&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;print "$string" |&lt;BR /&gt;awk '/\([0-9]+\) {&lt;BR /&gt;for ( i=1;i&amp;lt;=NF;i++;) {&lt;BR /&gt;if ( $i ~ /[a-zA-Z0-9]+\([0-9]+\).*/ ) {&lt;BR /&gt;split($i,a,"(");&lt;BR /&gt;split(a[2],b,")");&lt;BR /&gt;printf("%s = %s\n",a[1],b[1]);&lt;BR /&gt;}}}'</description>
      <pubDate>Wed, 19 Nov 2003 15:11:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123866#M802905</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-11-19T15:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123867#M802906</link>
      <description>2. yes like you said I want to take the value v1(100) and put that in a string s1 and v2(50) in s2. ie. s1=100 and s2=50. &lt;BR /&gt;&lt;BR /&gt;as long as v1 is before v2, you could do this&lt;BR /&gt;&lt;BR /&gt;print "$string" |&lt;BR /&gt;awk '/\([0-9]+\) {&lt;BR /&gt;for ( i=1;i&amp;lt;=NF;i++;) {&lt;BR /&gt;if ( $i ~ /[a-zA-Z0-9]+\([0-9]+\).*/ ) {&lt;BR /&gt;split($i,a,"(");&lt;BR /&gt;split(a[2],b,")");&lt;BR /&gt;printf("%s\n",b[1]);&lt;BR /&gt;}}}' |&lt;BR /&gt;read s1 s2 junk&lt;BR /&gt;print "s1 = $s1\ns2 = $s2"</description>
      <pubDate>Wed, 19 Nov 2003 15:15:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123867#M802906</guid>
      <dc:creator>curt larson_1</dc:creator>
      <dc:date>2003-11-19T15:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123868#M802907</link>
      <description>When you say it doesn't work, does it not set val1 and val2 to the numbers from the string? For instance-&lt;BR /&gt; &lt;BR /&gt;$ x="Hi this is a big string and i am trying to parse it this contains values v1(100) and v2(50)" &lt;BR /&gt;$ set -- `echo "$x" | sed -e 's/[^(]*(\([0-9]*\))/ \1/g'`&lt;BR /&gt;$ val1=$1&lt;BR /&gt;$ val2=$2&lt;BR /&gt;$ echo $val1&lt;BR /&gt;100&lt;BR /&gt;$ echo $val2&lt;BR /&gt;50&lt;BR /&gt; &lt;BR /&gt;I run the above and I get the 2 numbers you want out of the string...&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 19 Nov 2003 15:20:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123868#M802907</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-11-19T15:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123869#M802908</link>
      <description>Hi,&lt;BR /&gt;Thanks. It works. I had some other problem in the script.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Wed, 19 Nov 2003 15:38:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123869#M802908</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-19T15:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123870#M802909</link>
      <description>Hi Rodney,&lt;BR /&gt;&lt;BR /&gt;The value of the big string I am obtaining is from running a process.&lt;BR /&gt;&lt;BR /&gt;I get that by &lt;BR /&gt;&lt;BR /&gt;s1= `echo  execprocess | grep..... etc`&lt;BR /&gt;&lt;BR /&gt;Then I was using this string against the expr. you gave.&lt;BR /&gt;&lt;BR /&gt; set -- `echo "$s1" | sed -e 's/[^(]*(\([0-9]*\))/ \1/g'`&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;It looks like this string contains lots of sp. chars and line breaks etc.&lt;BR /&gt;&lt;BR /&gt;My question is how can I make this string  a coherent one to fit into your expr.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;dude.</description>
      <pubDate>Wed, 19 Nov 2003 16:23:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123870#M802909</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-19T16:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123871#M802910</link>
      <description>Oh, the plot thickens...&lt;BR /&gt; &lt;BR /&gt;Are you saying that s1 will contain multiple lines in it?&lt;BR /&gt; &lt;BR /&gt;s1= `echo execprocess | grep..... etc`&lt;BR /&gt; &lt;BR /&gt;If that be the case, then I recommend you don't put the results of execprocess into "s1". Rather put the lines to a file like /tmp/myoutput. Then in your shell script, loop through reading one line at a time into variable s1 from /tmp/myoutput and then you can parse each line individually.&lt;BR /&gt; &lt;BR /&gt;If this starts getting more complicated, I would recommend you use a tool like "awk" or better yet "perl" to process the output from execprocess.&lt;BR /&gt; &lt;BR /&gt;Good Luck&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Wed, 19 Nov 2003 17:13:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123871#M802910</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-11-19T17:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123872#M802911</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;here is another try. Assign the output to s1. &lt;BR /&gt;&lt;BR /&gt;Val1=`expr ${s1} : ".*v1.\($[0-9]\)"`&lt;BR /&gt;Val2=`expr ${s1} : ".*v2.\($[0-9]\)"`&lt;BR /&gt;&lt;BR /&gt;hows that? Got no chance to test it however.&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Nov 2003 18:33:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123872#M802911</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-11-19T18:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123873#M802912</link>
      <description>Oops, too tired!!&lt;BR /&gt;&lt;BR /&gt;Val2=`expr ${s1} : ".*v2.\([0-9]*\)"`&lt;BR /&gt;&lt;BR /&gt;greetings,&lt;BR /&gt;&lt;BR /&gt;Michael&lt;BR /&gt;</description>
      <pubDate>Wed, 19 Nov 2003 18:40:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123873#M802912</guid>
      <dc:creator>Michael Schulte zur Sur</dc:creator>
      <dc:date>2003-11-19T18:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123874#M802913</link>
      <description>Why not this way: strip all text outsite the brackets, leaving only the result string in the two variables (and remember the space to be put between the variables:&lt;BR /&gt;&lt;BR /&gt;strip=$(echo $s1 | sed -e 's/^[^(]*(//' -e 's/)[^(]*(/ /g' -e 's/).*$//')&lt;BR /&gt;&lt;BR /&gt;Then it is easy to set your variables:&lt;BR /&gt;set -- $strip&lt;BR /&gt;v1=$1&lt;BR /&gt;v2=$2&lt;BR /&gt;&lt;BR /&gt;You can also test the number of variables in string s1 this way, for instance. It could be more or less then two and this sed instruction should still work... though the assignment will not set v2 or ignore extra values.&lt;BR /&gt;</description>
      <pubDate>Thu, 20 Nov 2003 01:27:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123874#M802913</guid>
      <dc:creator>Elmar P. Kolkman</dc:creator>
      <dc:date>2003-11-20T01:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123875#M802914</link>
      <description>I have fixed the issue.&lt;BR /&gt;&lt;BR /&gt;Thank you all guys!</description>
      <pubDate>Thu, 20 Nov 2003 16:54:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123875#M802914</guid>
      <dc:creator>dude70</dc:creator>
      <dc:date>2003-11-20T16:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: Parsing a string</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123876#M802915</link>
      <description>Dude,&lt;BR /&gt;&lt;BR /&gt;Can you share your solution with the rest of the forum?&lt;BR /&gt; &lt;BR /&gt;Then we all benefit...&lt;BR /&gt; &lt;BR /&gt;-- Rod Hills</description>
      <pubDate>Thu, 20 Nov 2003 17:47:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/parsing-a-string/m-p/3123876#M802915</guid>
      <dc:creator>Rodney Hills</dc:creator>
      <dc:date>2003-11-20T17:47:29Z</dc:date>
    </item>
  </channel>
</rss>

