<?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 question - cut or awk function to get first field in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757945#M101751</link>
    <description>Clay, you are correct.   I provided shell syntax and wanted the equivalent syntax for perl.</description>
    <pubDate>Fri, 24 Mar 2006 09:39:40 GMT</pubDate>
    <dc:creator>Jack C. Mahaffey</dc:creator>
    <dc:date>2006-03-24T09:39:40Z</dc:date>
    <item>
      <title>Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757936#M101742</link>
      <description>Got a variable named $var1&lt;BR /&gt;Contains "a b c"&lt;BR /&gt;&lt;BR /&gt;I want to put the first value in $var2.&lt;BR /&gt;&lt;BR /&gt;What's the syntax similar to :&lt;BR /&gt;var2=`echo $var1 | awk ' { print $1 } '&lt;BR /&gt;&lt;BR /&gt;OR &lt;BR /&gt;var2='echo $var1 | cut -d  -f 1`&lt;BR /&gt;&lt;BR /&gt;I think the split function will do it but can't remember how.&lt;BR /&gt;&lt;BR /&gt;jack...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 16:45:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757936#M101742</guid>
      <dc:creator>Jack C. Mahaffey</dc:creator>
      <dc:date>2006-03-23T16:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757937#M101743</link>
      <description>&lt;BR /&gt;&lt;BR /&gt;How about:&lt;BR /&gt;echo "${var1}" | read var2 dummy1 dummy2&lt;BR /&gt;echo "var2 = \"${var2}\""&lt;BR /&gt;&lt;BR /&gt;It's all internal to the shell.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 16:53:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757937#M101743</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-03-23T16:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757938#M101744</link>
      <description>Hi Jack:&lt;BR /&gt;&lt;BR /&gt;# perl -le '$x="a b c";@fields=split(/\s+/,$x);print $fields[0]'&lt;BR /&gt;&lt;BR /&gt;...splits on whitespace, for instance.  Fields in erl are 0-relative, so the first one is [0].&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 23 Mar 2006 16:59:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757938#M101744</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-23T16:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757939#M101745</link>
      <description>Thanks...</description>
      <pubDate>Thu, 23 Mar 2006 17:00:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757939#M101745</guid>
      <dc:creator>Jack C. Mahaffey</dc:creator>
      <dc:date>2006-03-23T17:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757940#M101746</link>
      <description>You asked in Perl but your syntax is so bad for Perl that I assumed that this was a shell question but if it's Perl then something like this:&lt;BR /&gt;&lt;BR /&gt;my $var1 = "a b c";&lt;BR /&gt;my @var2 = split /\s+/,$var1&lt;BR /&gt;print "var2 = ",$var2[0],"\n";&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 17:04:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757940#M101746</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-03-23T17:04:31Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757941#M101747</link>
      <description>Jack,&lt;BR /&gt;&lt;BR /&gt;Just wondering why your own awk contruct will not work? It works for me :)&lt;BR /&gt;&lt;BR /&gt;# var1="a b c"&lt;BR /&gt;# var2=`echo $var1 | awk '{print $1}`&lt;BR /&gt;# echo $var2&lt;BR /&gt;a&lt;BR /&gt;&lt;BR /&gt;cheers!</description>
      <pubDate>Thu, 23 Mar 2006 17:36:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757941#M101747</guid>
      <dc:creator>Sandman!</dc:creator>
      <dc:date>2006-03-23T17:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757942#M101748</link>
      <description>Hi (again) Jack:&lt;BR /&gt;&lt;BR /&gt;It's worth mentioning, since you asked about Perl in comparison to 'awk', that its easy to extract fields from files thusly:&lt;BR /&gt;&lt;BR /&gt;# perl -nalF: -e 'print $F[0] if /^j/i' /etc/passwd &lt;BR /&gt;&lt;BR /&gt;The above reads '/etc/passwd' and prints all logins that begin with "j" in lower or upper case.&lt;BR /&gt;&lt;BR /&gt;The '-n' generates a read-loop to read the datafile.  The '-a' arms automatic splitting of the records read using a field seperator defined by '-F' --- here the colon (:").  The '-l' adds a newline to every print statement.  Each element split from the record is placed in the @F array which is automatically provided.  Again, the first element is zero-relative.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 20:33:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757942#M101748</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-03-23T20:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757943#M101749</link>
      <description>JRF... I was going to write that :-). Thanks.&lt;BR /&gt;&lt;BR /&gt;&amp;gt;&amp;gt; Got a variable named $var1&lt;BR /&gt;&amp;gt;&amp;gt; Contains "a b c"&lt;BR /&gt;&lt;BR /&gt;If you are truly interested in using Perl, then you should probably take step back and see how the value got into that variable, and what will be done with $var2 once you get that. Print it? Use it as a part of a command?&lt;BR /&gt;Maybe using perl whilest getting $var1 tru using $var2 can solve multiple problems at once.&lt;BR /&gt;&lt;BR /&gt;To put it differently... &lt;BR /&gt;What problem are you really trying to solve?&lt;BR /&gt;Surely gettting a field from a variable is just a minor sub task. What is the next level up task, and perhaps the next level up from there? Maybe there a neat all-perl solution instead of shell + perl/awk.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 21:10:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757943#M101749</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-03-23T21:10:27Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757944#M101750</link>
      <description>Oops, ignore my prior reply.&lt;BR /&gt;I thought $var1 was a shell variable, but now I see it may have been a perl variable already.&lt;BR /&gt;The shell scripting threw me of.&lt;BR /&gt;&lt;BR /&gt;Just for grins... &lt;BR /&gt;If it was a shell variable, the you can do something like: &lt;BR /&gt;$ var1="aap noot mies"&lt;BR /&gt;$ echo $var1 | perl -ple '$_ = (split)[0]'&lt;BR /&gt;aap&lt;BR /&gt;&lt;BR /&gt;That works because -p implies a loop reading data into $_ and printing whatever is left in $_ at each loop itteration.&lt;BR /&gt;The 'split' produces an array splitting by default on whitespace and taking input from $_&lt;BR /&gt;&lt;BR /&gt;And using the -a autosplit into @F gives:&lt;BR /&gt;&lt;BR /&gt;$ echo $var1 | perl -pale '$_ = @F[0]'&lt;BR /&gt;aap&lt;BR /&gt;&lt;BR /&gt;Hein.&lt;BR /&gt;</description>
      <pubDate>Thu, 23 Mar 2006 21:27:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757944#M101750</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-03-23T21:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757945#M101751</link>
      <description>Clay, you are correct.   I provided shell syntax and wanted the equivalent syntax for perl.</description>
      <pubDate>Fri, 24 Mar 2006 09:39:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757945#M101751</guid>
      <dc:creator>Jack C. Mahaffey</dc:creator>
      <dc:date>2006-03-24T09:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Perl question - cut or awk function to get first field</title>
      <link>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757946#M101752</link>
      <description>Thanks all for your feedback.   My bad for not being very clear in my post.  &lt;BR /&gt;&lt;BR /&gt;I just needed the corresponding perl sytax to capture the first value and then place that value into a variable that I can use later in the perl script.&lt;BR /&gt;&lt;BR /&gt;I used the shell syntax in the original post in an attempt to show what I was wanting to do in perl.   Looking for perl equivalent syntax.&lt;BR /&gt;&lt;BR /&gt;Jack...&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 24 Mar 2006 09:54:36 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/perl-question-cut-or-awk-function-to-get-first-field/m-p/3757946#M101752</guid>
      <dc:creator>Jack C. Mahaffey</dc:creator>
      <dc:date>2006-03-24T09:54:36Z</dc:date>
    </item>
  </channel>
</rss>

