Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6877179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:34:09+00:00 2026-05-27T04:34:09+00:00

One of the cool things about Ruby is its ability to behave like typical

  • 0

One of the cool things about Ruby is its ability to behave like typical Unix command-line tools, to do things like (similar to the example from the official documentation):

$ echo "matz" | ruby -pe '$_.upcase!'
MATZ

Awk, on the other hand can perform an aggregation on lines from standard input, e.g., summing a sequence of numbers:

$ for (( i=0; $i < 50; i++ )); do echo $i; done | awk 'BEGIN { tot=0; } { tot += $0 } END { print tot }'
1225

I’d like to know if it’s possible to get Ruby to do what is being achieved by the Awk BEGIN and END blocks above so as to be able to do similar aggregation operations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:34:09+00:00Added an answer on May 27, 2026 at 4:34 am
    seq 49 | ruby -pe 'BEGIN { $tot=0 }; $tot += $_.to_i; END { print $tot }'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of the cool things about the .NET Compact Framework is that you can
Ruby/Rails does lots of cool stuff when it comes to sugar for basic things,
I have a cool snippet of code that works well, except one thing. The
Hey I was just wondering if there is a cool one liner that would
Hudson CI server displays stability weather which is cool. And it allows one project
One of my biggest typographical frustrations about HTML is the way that it mangles
I'm very new to JQuery, but I was told the one of the cool
Ruby looks a very cool language. I've started learning it for the past two
This will be my first time creating one of those slider things. I've seen
I've been trying for some time to put some 'cool' things I've been reading

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.