<?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: Perl - Simple field delimeter based extraction in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915282#M103889</link>
    <description>Problem solved.  Next I have some xml to parse with Perl so I may end up asking more questions shortly.</description>
    <pubDate>Wed, 03 Aug 2005 00:33:18 GMT</pubDate>
    <dc:creator>Daavid Turnbull</dc:creator>
    <dc:date>2005-08-03T00:33:18Z</dc:date>
    <item>
      <title>Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915276#M103883</link>
      <description>If I had my Camel book to hand I would hope that I could nut this one out.  Basically I need to extract a field, delimeted by '|' (vertical bars) from a single line and use it as a key to grep a line from an other file.&lt;BR /&gt;&lt;BR /&gt;The line might look like:&lt;BR /&gt;&lt;BR /&gt;field number one|field number two|field 3 etc.&lt;BR /&gt;&lt;BR /&gt;I am assuming that this can be done with a simple expression... as opposed to breaking up the string using tokens but my mind is blank as to how this may look syntax wise at the moment.</description>
      <pubDate>Sun, 31 Jul 2005 19:20:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915276#M103883</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-07-31T19:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915277#M103884</link>
      <description>Sure. Easy&lt;BR /&gt;&lt;BR /&gt;my %keys;&lt;BR /&gt;open my $key_file, "&lt;LINES.TXT&gt;&lt;/LINES.TXT&gt;while (&amp;lt;$key_file&amp;gt;) {&lt;BR /&gt; chomp;&lt;BR /&gt; # assuming the key is the first field&lt;BR /&gt; my ($key, @fields) = split m/\|/, $_, -1;&lt;BR /&gt; $keys{$key} = [ @fields ];&lt;BR /&gt;&lt;BR /&gt; # alternatively, if you don't need the other&lt;BR /&gt; # fields, and field 5 is your key&lt;BR /&gt; $keys{(split /\|/, $_, -1)[4]}++;&lt;BR /&gt; }&lt;BR /&gt;close $key_file;&lt;BR /&gt;&lt;BR /&gt;# Now parse the other file(s)&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt; my @fields = split m/\|/, $_, -1;&lt;BR /&gt; # See if field 3 (1-based, perl is 0-based)&lt;BR /&gt; # exists in your keys&lt;BR /&gt; exists $key{$fields[2]} or next;&lt;BR /&gt; # line accepted, process&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 01 Aug 2005 01:36:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915277#M103884</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2005-08-01T01:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915278#M103885</link>
      <description>You can try as,&lt;BR /&gt;&lt;BR /&gt;echo "hi|bye|see|you" | perl -ne '@keys=split(/\|/); print @keys;'&lt;BR /&gt;&lt;BR /&gt;Use @keys to grep the line in a file.&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Mon, 01 Aug 2005 01:42:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915278#M103885</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-01T01:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915279#M103886</link>
      <description>You can try with a script also as,&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;&lt;BR /&gt;# single Line&lt;BR /&gt;$_="first|second|third|four|fifth";&lt;BR /&gt;@keys=split (/\|/);&lt;BR /&gt;$FILE="/tmp/test.log";&lt;BR /&gt;&lt;BR /&gt;open(FH,$FILE) || die "Can not open file: $!";&lt;BR /&gt;&lt;BR /&gt;while (&lt;FH&gt;) {&lt;BR /&gt;&lt;BR /&gt; foreach $key (@keys)&lt;BR /&gt; {&lt;BR /&gt;   print $_ if ( m/$key/);&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;# end #&lt;BR /&gt;&lt;BR /&gt;hth.&lt;/FH&gt;</description>
      <pubDate>Mon, 01 Aug 2005 01:52:19 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915279#M103886</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-08-01T01:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915280#M103887</link>
      <description>Thanks for the responses.&lt;BR /&gt;&lt;BR /&gt;All these work and work remarkably well.&lt;BR /&gt;&lt;BR /&gt;I will assign points after I have coded and tested based on what I have learned.</description>
      <pubDate>Mon, 01 Aug 2005 18:54:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915280#M103887</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-08-01T18:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915281#M103888</link>
      <description>My app was a little more convoluted but what I learned from your posts was spot on.  I assigned 10 points each.</description>
      <pubDate>Wed, 03 Aug 2005 00:32:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915281#M103888</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-08-03T00:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - Simple field delimeter based extraction</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915282#M103889</link>
      <description>Problem solved.  Next I have some xml to parse with Perl so I may end up asking more questions shortly.</description>
      <pubDate>Wed, 03 Aug 2005 00:33:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-simple-field-delimeter-based-extraction/m-p/4915282#M103889</guid>
      <dc:creator>Daavid Turnbull</dc:creator>
      <dc:date>2005-08-03T00:33:18Z</dc:date>
    </item>
  </channel>
</rss>

