Awk equivalent in ruby

HI
how to use awk equivalent in ruby

in bash i can use , awk to get the value 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1

but in ruby , how can i get the value 1 ??

···

--
Posted via http://www.ruby-forum.com/.

HI
how to use awk equivalent in ruby

in bash i can use , awk to get the value 1

how?

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1

which '1' ???

but in ruby , how can i get the value 1 ??

- puts 1 :slight_smile:

- google for 'ruby regular expressions'
   (especially capturing might be useful)

···

Am 05.09.2012 21:19, schrieb Ferdous ara:

--
<https://github.com/stomar/>

Ferdous ara wrote in post #1074829:

HI
how to use awk equivalent in ruby

in bash i can use , awk to get the value 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56

= INTEGER: 1

As a one-liner, awk-style?

  echo "Foo.1.2.3 = INTEGER: 1" | ruby -ane 'puts $F[3]'

In a ruby script?

  str = "Foo.1.2.3 = INTEGER: 1"
  a, b, c, d = str.split
  puts d

This is assuming the '1' you want is the one at the end of the line.

···

--
Posted via http://www.ruby-forum.com/.

This question was asked in a very confusing way, I didn't realize `=
INTEGER: 1` was part of the input, I thought it was the result you expected
to get after doing some sort of analysis on the line above it.

Anyway, to expand on Brian's answer:

$ cat f
FC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1
RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1

$ ruby -ane 'puts $F[2] if /^= INTEGER: /' < f
1
1
1
1
1
1
1
1

···

On Wed, Sep 5, 2012 at 2:19 PM, Ferdous ara <lists@ruby-forum.com> wrote:

HI
how to use awk equivalent in ruby

in bash i can use , awk to get the value 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.49.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.48.46.51.50.55.54.56
= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.49.46.51.50.55.54.56
= INTEGER: 1

which '1' ???

i just need 1 thats it

- google for 'ruby regular expressions'
   (especially capturing might be useful)

I am reading in google. but very new in ruby ..
so bit confused .. ,
if you can give me some example that would be good
Thanks

···

--
Posted via http://www.ruby-forum.com/.

Josh Cheek wrote in post #1075006:

Anyway, to expand on Brian's answer:

$ cat f

FC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.49.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.48.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.49.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.48.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.49.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.48.46.51.50.55.54.56

= INTEGER: 1

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.49.46.51.50.55.54.56

= INTEGER: 1

$ ruby -ane 'puts $F[2] if /^= INTEGER: /' < f
1
1
1
1
1
1
1
1

Josh has assumed that these are pairs of lines. I think this was just an
artefact of formatting by the OP's mail client, and they are really
single lines. In that case you just want the 4th column of each line:

ruby -ane 'puts $F[3]' < f

···

--
Posted via http://www.ruby-forum.com/.

which '1' ???

i just need 1 thats it

???

and: what would you do in awk?

- google for 'ruby regular expressions'

> (especially capturing might be useful)

I am reading in google. but very new in ruby ..
so bit confused .. ,
if you can give me some example that would be good
Thanks

1.9.3-p194 :001 > string = 'a string with 27 characters'
  => "a string with 27 characters"
1.9.3-p194 :002 > /(?<number>\d+) characters/ =~ string
  => 14
1.9.3-p194 :003 > number
  => "27"

see <http://www.ruby-doc.org/core-1.9.3/Regexp.html>

look for 'named capture groups'

···

Am 05.09.2012 21:57, schrieb Ferdous ara:

--
<https://github.com/stomar/>

Oh, you're probably right. This was submitted via Ruby Forum, which does
wrap lines IIRC. No wonder the data was so confusing >.<

Is this a setting someone could turn off? I think it is objectively
incorrect to wrap lines for people. Their display software (in my case,
Gmail) should be responsible for determining the presentation settings
(line width), not the input source. The input source (Ruby Forum) has no
idea, and is making incorrect assumptions about my display, which is
causing problems.

···

On Fri, Sep 7, 2012 at 4:56 AM, Brian Candler <lists@ruby-forum.com> wrote:

Josh Cheek wrote in post #1075006:
> Anyway, to expand on Brian's answer:
>
> $ cat f
>

FC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.48.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.13.118.99.112.45.48.47.49.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.48.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.48.47.48.47.49.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.48.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.49.47.48.47.49.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.48.46.51.50.55.54.56
> = INTEGER: 1
>

RFC1155-SMI::enterprises.2636.3.40.1.4.1.2.1.3.1.15.118.99.112.45.50.47.48.47.49.46.51.50.55.54.56
> = INTEGER: 1
>
>
> $ ruby -ane 'puts $F[2] if /^= INTEGER: /' < f
> 1
> 1
> 1
> 1
> 1
> 1
> 1
> 1

Josh has assumed that these are pairs of lines. I think this was just an
artefact of formatting by the OP's mail client, and they are really
single lines. In that case you just want the 4th column of each line:

ruby -ane 'puts $F[3]' < f

or for simple cases:

title = 'Snow White and the 7 Dwarfs'
title[/\d+/] # => "7"

···

--
<https://github.com/stomar/>

People should just learn to use pastebins.

-- Matma Rex

What happens when the pastebin goes down?

-Josh

···

On Sat, Sep 8, 2012 at 5:09 AM, Bartosz Dziewoński <matma.rex@gmail.com>wrote:

People should just learn to use pastebins.

-- Matma Rex