<?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: ksh: parse a file with different field separator in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880401#M495097</link>
    <description>&lt;P&gt;&amp;gt; My choice is to use awk to grab the fields you need [...]&lt;/P&gt;&lt;P&gt;&amp;gt; [...] $2,$4 [...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Ok, if you _know_ in which order the fields apppear.&lt;/P&gt;&lt;P&gt;&amp;gt; I want to get the value ( in double quotes ) after -host [...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Knowing nothing about the source of these data, if someone tells me&lt;BR /&gt;"after -host", then I tend to look for "-host", and take what comes&lt;BR /&gt;after it.&amp;nbsp; Someone who knows more than I may assume things which I&lt;BR /&gt;won't.&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jul 2016 16:10:07 GMT</pubDate>
    <dc:creator>Steven Schweda</dc:creator>
    <dc:date>2016-07-20T16:10:07Z</dc:date>
    <item>
      <title>ksh: parse a file with different field separator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880270#M495094</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;i have files ( example of data protector file "cell_info" ) with different fields and i think different field separators.&lt;/P&gt;&lt;P&gt;example :&lt;/P&gt;&lt;PRE&gt;-host "server_dp_06_20" -os "hp ia64 hp-ux-11.31" -core A.06.20 -integ A.06.20 -cs A.06.20 -da A.06.20 -ma A.06.20 -cc A.06.20 -javagui A.06.20 -oracle8 A.06.20 -docs A.06.20
-host "server_dp_09_20" -os "gpl x86_64 linux-2.6.16.60-0.103.1-smp" -core A.09.00 -integ A.09.00 -da A.09.00 -ma A.09.00 -cc A.09.00 -oracle8 A.09.00 -autodr A.09.00 -ts_core A.09.00 -corepatch A.09.06 -integpatch A.09.06 -dapatch A.09.06 -mapatch A.09.06 -ccpatch A.09.06 -oracle8patch A.09.06 -autodrpatch A.09.06 -ts_corepatch A.09.06&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;i want to get the value ( in double quotes ) after&lt;STRONG&gt; -host &lt;/STRONG&gt;and &lt;STRONG&gt;-os. &lt;/STRONG&gt;so in first line after -host&amp;nbsp; : "server_dp_06_20"&amp;nbsp;&amp;nbsp; and after -os&amp;nbsp;"hp ia64 hp-ux-11.31" &lt;STRONG&gt;.&lt;/STRONG&gt; i tried while IFS="-" read value1 value1 etc&amp;nbsp; and with awk i have problem the different fields. any idea ?&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 13:30:39 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880270#M495094</guid>
      <dc:creator>support_billa</dc:creator>
      <dc:date>2016-07-20T13:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: ksh: parse a file with different field separator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880294#M495095</link>
      <description>&lt;P&gt;&amp;gt; I want to get the value ( in double quotes ) after -host [...]&lt;/P&gt;&lt;P&gt;mba$ line='-host "server_dp_06_20" -os "hp ia64 hp-ux-11.31" -core A.06.20'&lt;/P&gt;&lt;P&gt;mba$ echo "$line" | sed -e 's/-host "\([^"]*\)".*/\1/'&lt;BR /&gt;server_dp_06_20&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Or, if you want to include the quotation marks in the result:&lt;/P&gt;&lt;P&gt;mba$ echo "$line" | sed -e 's/-host \("[^"]*"\).*/\1/'&lt;BR /&gt;"server_dp_06_20"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; If you can't do it with "sed", then it's not worth doing, I always&lt;BR /&gt;say.&amp;nbsp; This example was done on a Mac, but at my level of expertise,&lt;BR /&gt;"sed" is "sed".&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 13:59:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880294#M495095</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2016-07-20T13:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: ksh: parse a file with different field separator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880389#M495096</link>
      <description>&lt;P&gt;My choice is to&amp;nbsp;use awk to grab the fields you need using the -F \" option as the&amp;nbsp;separator.&lt;BR /&gt;Here is the result with awk:&lt;/P&gt;&lt;PRE&gt;TXT='-host "server_dp_06_20" -os "hp ia64 hp-ux-11.31" -core A.06.20 -integ A.06...'
-host "server_dp_09_20" -os "gpl x86_64 linux-2.6.16.60-0.103.1-smp" -core A.09....'  

echo "$TXT" | awk -F \"  '{print $2,$4}'
server_dp_06_20 hp ia64 hp-ux-11.31&lt;BR /&gt;server_dp_09_20 gpl x86_64 linux-2.6.16.60-0.103.1-smp&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Since the data fields may contain spaces, you can run the awk command for each variable:&lt;/P&gt;&lt;PRE&gt;TXT='-host "server_dp_06_20" -os "hp ia64 hp-ux-11.31" -core A.06.20 -integ A.06...' -cs...'&lt;BR /&gt;-host "server_dp_09_20" -os "gpl x86_64 linux-2.6.16.60-0.103.1-smp" -core A.09...'&lt;BR /&gt;&lt;BR /&gt;SERVERNAME="$(echo "$TXT" | awk -F \"  '{print $2}')"&lt;BR /&gt;OS="$(echo "$TXT" | awk -F \" '{print $4}')"&lt;BR /&gt;echo "Server: $SERVERNAME, OS: $OS"&lt;BR /&gt;Server: server_dp_06_20, OS: hp ia64 hp-ux-11.3&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;If this script is being used to read a long file, just use read to assign the TXT variable:&lt;/P&gt;&lt;PRE&gt;cat $SOMEFILE | while read TXT
do
   SERVERNAME="$(echo "$TXT" | awk -F \"  '{print $2}')"
   OS="$(echo "$TXT" | awk -F \" '{print $4}')"
   echo "Server: $SERVERNAME, OS: $OS"
done&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 15:54:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880389#M495096</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2016-07-20T15:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: ksh: parse a file with different field separator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880401#M495097</link>
      <description>&lt;P&gt;&amp;gt; My choice is to use awk to grab the fields you need [...]&lt;/P&gt;&lt;P&gt;&amp;gt; [...] $2,$4 [...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Ok, if you _know_ in which order the fields apppear.&lt;/P&gt;&lt;P&gt;&amp;gt; I want to get the value ( in double quotes ) after -host [...]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Knowing nothing about the source of these data, if someone tells me&lt;BR /&gt;"after -host", then I tend to look for "-host", and take what comes&lt;BR /&gt;after it.&amp;nbsp; Someone who knows more than I may assume things which I&lt;BR /&gt;won't.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jul 2016 16:10:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6880401#M495097</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2016-07-20T16:10:07Z</dc:date>
    </item>
    <item>
      <title>Re: ksh: parse a file with different field separator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6881090#M495098</link>
      <description>&lt;P&gt;The man page of the hp-ux version awk that I tried this on does not document support gensub or any other method of using a captured group as replacement text. So something like this may work:&lt;/P&gt;&lt;PRE&gt;awk 'match($0, "-host [^ ]* -os [^ ]*") { $0=substr($0, RSTART, RLENGTH); sub("-host ",""); sub ("-os ", ""); print; }'&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Jul 2016 08:15:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6881090#M495098</guid>
      <dc:creator>ranganath ramachandra</dc:creator>
      <dc:date>2016-07-22T08:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: ksh: parse a file with different field separator</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6881492#M495099</link>
      <description>&lt;P&gt;You you can write a program in awk to look at each field.&lt;/P&gt;&lt;P&gt;awk '&lt;BR /&gt;{&lt;BR /&gt;host = ""&lt;BR /&gt;os = ""&lt;BR /&gt;for (i = 1; i &amp;lt; NF; ++i) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ($i == "-os") {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os = $(i+1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ++i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # find next quote&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (;i &amp;lt; NF; ) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j = index(substr(os, 2), "\"")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (j &amp;gt; 0) break&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; os = os " " $(i+1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ++i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp;&amp;nbsp; } else if ($i == "-host") {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; host = $(i+1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ++i&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;print "host=" host "; os=" os&lt;BR /&gt;}'&amp;nbsp; input-file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 24 Jul 2016 10:47:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/ksh-parse-a-file-with-different-field-separator/m-p/6881492#M495099</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2016-07-24T10:47:29Z</dc:date>
    </item>
  </channel>
</rss>

