awk?

Hi All,

How to I translate this to Perl 6?   I am looking to be able
to dig out the fourth (or any) data point.

<code>
#!bin/bash
$x=$(echo "total kB          180448    2980     112" | awk '{print $4}')
echo $x
</code>

2980


Many thanks,
-T
0
ToddAndMargo
4/13/2018 10:00:22 AM
perl.perl6.users 929 articles. 0 followers. Follow

7 Replies
11 Views

Similar Articles

[PageSpeed] 15

Hi Todd,

On Fri, 13 Apr 2018 03:00:22 -0700
ToddAndMargo <ToddAndMargo@zoho.com> wrote:

> echo "total kB          180448    2980     112" | awk '{print $4}')

shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" | pe=
rl6
-n -e 'say .split(/\s+/)[3]'

2980

shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" | awk
'{print $4}'

2980

See https://docs.perl6.org/language/5to6-nutshell#-a and
http://perldoc.perl.org/perlrun.html .

--=20
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
What does =E2=80=9CZionism=E2=80=9D mean? - http://shlom.in/def-zionism

G=C3=B6del=E2=80=99s Incompleteness Theorem is about to be replaced by the
[Clarissa] Darling =E2=80=9CLike, Totally!=E2=80=9D Completeness Theorem.
    =E2=80=94 http://www.shlomifish.org/humour/bits/facts/Clarissa/

Please reply to list if it's a mailing list post - http://shlom.in/reply .
0
shlomif
4/13/2018 10:31:12 AM
--000000000000dd77080569b8f795
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi,

Since "There's More Than One Way To Do It", one can look for the value,
instead of the separator:

$ echo "total kB          180448    2980     112" |perl6 -n -e 'say
..comb(/\d+/)[1]'
2980


On Fri, Apr 13, 2018 at 12:31 PM, Shlomi Fish <shlomif@shlomifish.org>
wrote:

> Hi Todd,
>
> On Fri, 13 Apr 2018 03:00:22 -0700
> ToddAndMargo <ToddAndMargo@zoho.com> wrote:
>
> > echo "total kB          180448    2980     112" | awk '{print $4}')
>
> shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" |
> perl6
> -n -e 'say .split(/\s+/)[3]'
>
> 2980
>
> shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" |
> awk
> '{print $4}'
>
> 2980
>
> See https://docs.perl6.org/language/5to6-nutshell#-a and
> http://perldoc.perl.org/perlrun.html .
>
> --
> -----------------------------------------------------------------
> Shlomi Fish       http://www.shlomifish.org/
> What does =E2=80=9CZionism=E2=80=9D mean? - http://shlom.in/def-zionism
>
> G=C3=B6del=E2=80=99s Incompleteness Theorem is about to be replaced by th=
e
> [Clarissa] Darling =E2=80=9CLike, Totally!=E2=80=9D Completeness Theorem.
>     =E2=80=94 http://www.shlomifish.org/humour/bits/facts/Clarissa/
>
> Please reply to list if it's a mailing list post - http://shlom.in/reply =
..
>



--=20
Fernando Santagata

--000000000000dd77080569b8f795
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi,<br><br></div>Since &quot;There&#39;s More Than On=
e Way To Do It&quot;, one can look for the value, instead of the separator:=
<br><br>$ echo &quot;total kB=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 180448=C2=A0=C2=A0=C2=A0 2980=C2=A0=C2=A0=C2=A0=C2=A0 112&quot; |=
perl6 -n -e &#39;say .comb(/\d+/)[1]&#39;<br>2980<br><br></div><div class=
=3D"gmail_extra"><br><div class=3D"gmail_quote">On Fri, Apr 13, 2018 at 12:=
31 PM, Shlomi Fish <span dir=3D"ltr">&lt;<a href=3D"mailto:shlomif@shlomifi=
sh.org" target=3D"_blank">shlomif@shlomifish.org</a>&gt;</span> wrote:<br><=
blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px=
 #ccc solid;padding-left:1ex">Hi Todd,<br>
<span class=3D""><br>
On Fri, 13 Apr 2018 03:00:22 -0700<br>
ToddAndMargo &lt;<a href=3D"mailto:ToddAndMargo@zoho.com">ToddAndMargo@zoho=
..com</a>&gt; wrote:<br>
<br>
&gt; echo &quot;total kB=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 180448=C2=A0 =C2=
=A0 2980=C2=A0 =C2=A0 =C2=A0112&quot; | awk &#39;{print $4}&#39;)<br>
<br>
</span>shlomif[Perl6]:$trunk$ echo &quot;total kB=C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 180448=C2=A0 =C2=A0 2980=C2=A0 =C2=A0 =C2=A0112&quot; | perl6<br=
>
-n -e &#39;say .split(/\s+/)[3]&#39;<br>
<br>
2980<br>
<br>
shlomif[Perl6]:$trunk$ echo &quot;total kB=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 180448=C2=A0 =C2=A0 2980=C2=A0 =C2=A0 =C2=A0112&quot; | awk<br>
&#39;{print $4}&#39;<br>
<br>
2980<br>
<br>
See <a href=3D"https://docs.perl6.org/language/5to6-nutshell#-a" rel=3D"nor=
eferrer" target=3D"_blank">https://docs.perl6.org/<wbr>language/5to6-nutshe=
ll#-a</a> and<br>
<a href=3D"http://perldoc.perl.org/perlrun.html" rel=3D"noreferrer" target=
=3D"_blank">http://perldoc.perl.org/<wbr>perlrun.html</a> .<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
-- <br>
------------------------------<wbr>------------------------------<wbr>-----=
<br>
Shlomi Fish=C2=A0 =C2=A0 =C2=A0 =C2=A0<a href=3D"http://www.shlomifish.org/=
" rel=3D"noreferrer" target=3D"_blank">http://www.shlomifish.org/</a><br>
What does =E2=80=9CZionism=E2=80=9D mean? - <a href=3D"http://shlom.in/def-=
zionism" rel=3D"noreferrer" target=3D"_blank">http://shlom.in/def-zionism</=
a><br>
<br>
G=C3=B6del=E2=80=99s Incompleteness Theorem is about to be replaced by the<=
br>
[Clarissa] Darling =E2=80=9CLike, Totally!=E2=80=9D Completeness Theorem.<b=
r>
=C2=A0 =C2=A0 =E2=80=94 <a href=3D"http://www.shlomifish.org/humour/bits/fa=
cts/Clarissa/" rel=3D"noreferrer" target=3D"_blank">http://www.shlomifish.o=
rg/<wbr>humour/bits/facts/Clarissa/</a><br>
<br>
Please reply to list if it&#39;s a mailing list post - <a href=3D"http://sh=
lom.in/reply" rel=3D"noreferrer" target=3D"_blank">http://shlom.in/reply</a=
> .<br>
</font></span></blockquote></div><br><br clear=3D"all"><br>-- <br><div clas=
s=3D"gmail_signature" data-smartmail=3D"gmail_signature">Fernando Santagata=
</div>
</div>

--000000000000dd77080569b8f795--
0
nando
4/13/2018 11:13:56 AM
One could also use .words --

$ echo "total kB          180448    2980     112" |perl6 -n -e 'say .words[3]'
2980

Brian

On Friday, April 13, Fernando Santagata wrote: 
> Hi,
> 
> Since "There's More Than One Way To Do It", one can look for the value,
> instead of the separator:
> 
> $ echo "total kB          180448    2980     112" |perl6 -n -e 'say
> .comb(/\d+/)[1]'
> 2980
> 
> 
> On Fri, Apr 13, 2018 at 12:31 PM, Shlomi Fish <shlomif@shlomifish.org>
> wrote:
> 
> > Hi Todd,
> >
> > On Fri, 13 Apr 2018 03:00:22 -0700
> > ToddAndMargo <ToddAndMargo@zoho.com> wrote:
> >
> > > echo "total kB          180448    2980     112" | awk '{print $4}')
> >
> > shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" |
> > perl6
> > -n -e 'say .split(/\s+/)[3]'
> >
> > 2980
> >
> > shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" |
> > awk
> > '{print $4}'
> >
> > 2980
> >
> > See https://docs.perl6.org/language/5to6-nutshell#-a and
> > http://perldoc.perl.org/perlrun.html .
> >
> > --
> > -----------------------------------------------------------------
> > Shlomi Fish       http://www.shlomifish.org/
> > What does “Zionism” mean? - http://shlom.in/def-zionism
> >
> > Gödel’s Incompleteness Theorem is about to be replaced by the
> > [Clarissa] Darling “Like, Totally!” Completeness Theorem.
> >     — http://www.shlomifish.org/humour/bits/facts/Clarissa/
> >
> > Please reply to list if it's a mailing list post - http://shlom.in/reply .
> >
> 
> 
> 
> -- 
> Fernando Santagata
0
bduggan2
4/13/2018 12:20:25 PM
On 04/13/2018 03:31 AM, Shlomi Fish wrote:
> Hi Todd,
> 
> On Fri, 13 Apr 2018 03:00:22 -0700
> ToddAndMargo <ToddAndMargo@zoho.com> wrote:
> 
>> echo "total kB          180448    2980     112" | awk '{print $4}')
> 
> shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" | perl6
> -n -e 'say .split(/\s+/)[3]'
> 
> 2980
> 
> shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" | awk
> '{print $4}'
> 
> 2980
> 
> See https://docs.perl6.org/language/5to6-nutshell#-a and
> http://perldoc.perl.org/perlrun.html .
> 

Aw bugger!  I forgot about split!  And I use it all the time.

Thank you!



-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
ToddAndMargo
4/13/2018 8:21:56 PM
>> On Fri, Apr 13, 2018 at 12:31 PM, Shlomi Fish <shlomif@shlomifish.org 
>> <mailto:shlomif@shlomifish.org>> wrote:
>> 
>>     Hi Todd,
>> 
>>     On Fri, 13 Apr 2018 03:00:22 -0700
>>     ToddAndMargo <ToddAndMargo@zoho.com <mailto:ToddAndMargo@zoho.com>>
>>     wrote:
>> 
>>     > echo "total kB          180448    2980     112" | awk '{print $4}')
>> 
>>     shlomif[Perl6]:$trunk$ echo "total kB          180448    2980   
>>       112" | perl6
>>     -n -e 'say .split(/\s+/)[3]'
>> 
>>     2980
>> 
>>     shlomif[Perl6]:$trunk$ echo "total kB          180448    2980   
>>       112" | awk
>>     '{print $4}'
>> 
>>     2980
>> 
>>     See https://docs.perl6.org/language/5to6-nutshell#-a
>>     <https://docs.perl6.org/language/5to6-nutshell#-a> and
>>     http://perldoc.perl.org/perlrun.html
>>     <http://perldoc.perl.org/perlrun.html> .
>> 


On 04/13/2018 04:13 AM, Fernando Santagata wrote:
> Hi,
> 
> Since "There's More Than One Way To Do It", one can look for the value, 
> instead of the separator:
> 
> $ echo "total kB          180448    2980     112" |perl6 -n -e 'say 
> .comb(/\d+/)[1]'
> 2980
> 

So the second d+ is [1].  Fascinating.  Thank you!
0
ToddAndMargo
4/13/2018 8:24:08 PM
>> On Friday, April 13, Fernando Santagata wrote:
>>> Hi,
>>>
>>> Since "There's More Than One Way To Do It", one can look for the value,
>>> instead of the separator:
>>>
>>> $ echo "total kB          180448    2980     112" |perl6 -n -e 'say
>>> .comb(/\d+/)[1]'
>>> 2980
>>>
>>>
>>> On Fri, Apr 13, 2018 at 12:31 PM, Shlomi Fish <shlomif@shlomifish.org>
>>> wrote:
>>>
>>>> Hi Todd,
>>>>
>>>> On Fri, 13 Apr 2018 03:00:22 -0700
>>>> ToddAndMargo <ToddAndMargo@zoho.com> wrote:
>>>>
>>>>> echo "total kB          180448    2980     112" | awk '{print $4}')
>>>>
>>>> shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" |
>>>> perl6
>>>> -n -e 'say .split(/\s+/)[3]'
>>>>
>>>> 2980
>>>>
>>>> shlomif[Perl6]:$trunk$ echo "total kB          180448    2980     112" |
>>>> awk
>>>> '{print $4}'
>>>>
>>>> 2980
>>>>
>>>> See https://docs.perl6.org/language/5to6-nutshell#-a and
>>>> http://perldoc.perl.org/perlrun.html .


>>> Fernando Santagata
On 04/13/2018 05:20 AM, Brian Duggan wrote:
> One could also use .words --
> 
> $ echo "total kB          180448    2980     112" |perl6 -n -e 'say .words[3]'
> 2980
> 
> Brian
> 

That almost exactly matches awk and I don't have to
wonder about what each value is made up of.  I love it.
Thank you!

-T

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0
ToddAndMargo
4/13/2018 8:26:07 PM
On 04/13/2018 04:13 AM, Fernando Santagata wrote:
> "There's More Than One Way To Do It"


The definition of Perl!

:-)
0
ToddAndMargo
4/13/2018 10:36:15 PM
Reply: