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

  • Home
  • SEARCH
  • 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 6878317
In Process

The Archive Base Latest Questions

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

I have a log file from a web server which looks like this; 1908

  • 0

I have a log file from a web server which looks like this;

1908 462
232 538
232 520
232 517

My task is to total column 1 and column 2 in a bash script. My desired output is;

2604 2037

I know of awk or sed which could go a long way to solving my problem but I can’t fathom how to actually do it. I’ve trawled examples on Google but haven’t turned up anything useful. Can someone point me in the right direction please?

  • 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:42:32+00:00Added an answer on May 27, 2026 at 4:42 am
    awk '{a += $1; b += $2} END { print a " " b }' foo.log
    

    (Note the complete lack of error checking.)

    EDIT :

    Ok, here’s a version with error checking:

    awk 'BEGIN { ok = 1 } { if (/^ *[0-9]+ +[0-9]+ *$/) { a += $1; b += $2 } else { ok = 0; exit 1 } } END { if (ok) print a, b }' foo.log
    

    If you don’t want to accept leading or trailing blanks, delete the two " *"s in the if statement.

    But this is big enough that it probably shouldn’t be a one-liner:

    #!/usr/bin/awk -f
    
    BEGIN {
        ok = 1
    }
    
    {
        if (/^ *[0-9]+ +[0-9]+ *$/) {
            a += $1
            b += $2
        }
        else {
            ok = 0
            exit 1
        }
    }
    
    END {
        if (ok) print a, b
    }
    

    There’s still no overflow or underflow checking, and it assumes that there will be no signs. The latter is easy enough to fix; the former would be more difficult. (Note that awk uses floating-point internally; if the sum is big enough, it could quietly lose precision.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a formatted string from a log file, which looks like: >>> a=test
I have a large server log file (~750 MB) which I can't open with
I have a log file containing statistics from different servers. I am separating the
i have a log file which contains hundreds/thousands of seperate XML messages and need
I am working with a log file and I have a method which is
I would like to log errors/informational and warning messages from within my web application
I'm trying to download a large .zip file from a web server but I
I have three dimensional array of data that is generated from web server logs
I have a log file in SqlServer that stores the time an application started,
I have a transaction log file in CSV format that I want use to

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.