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 7183281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:56:51+00:00 2026-05-28T17:56:51+00:00

i want to calculate: the total points (sum) the today points (sum) the total

  • 0

i want to calculate:

  • the total points (sum)
  • the today points (sum)
  • the total points (average)
  • the today points (average)

i have no idea with bash scripting other than i need to start with: #!/bin/bash

here’s a sample of my file

#file 14516 - 2011-01-26 19:01:00 EDT#
user: xxxxxxxx@email.com / id(11451611)
lastlogin: 1295896515
total_points: 11.76 / today: 5.21
gameid: 51

user: xxxxxxxx@email.com / id(11837327)
lastlogin: 1293893041
total_points: 416.1 / today: 98.1
gameid: 49

user: xxxxxxxx@email.com / id(11451611)
lastlogin: 1294917135
total_points: 1.76 / today: 0.21
gameid: 51
  • 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-28T17:56:52+00:00Added an answer on May 28, 2026 at 5:56 pm

    You can use this:

    #!/bin/bash
    
    if [ ! -f $1 ]; then
      echo "File $1 not found"
      exit 1
    fi
    
    number=$(grep total_points $1 | wc -l )
    sumTotal=$(grep total_points $1 | awk '{sum+=$2} END { print sum }')
    sumToday=$(grep total_points $1 | awk '{sum+=$5} END { print sum }')
    
    echo "Total SUM: $sumTotal"
    echo -n "Total AVG: "
    echo "scale=5;$sumTotal/$number" | bc
    
    echo "Today SUM: $sumToday"
    echo -n "Today AVG: "
    echo "scale=5;$sumToday/$number" | bc
    

    Then save to a file like: script.sh

    Change the permission to executable: chmod +x script.sh

    Then run it: ./script.sh sample.txt

    This will output:

    Total Record: 3
    Total SUM: 429.62
    Total AVG: 143.20666
    Today SUM: 103.52
    Today AVG: 34.50666
    

    Note:
    $1 will the the input file.

    Here’s more help about the bc command, grep, awk

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

Sidebar

Related Questions

I want to calculate the total number of nodes between a start node and
I want to calculate total memory used by a process in .net. Total memory
I want to calculate the sum of 1/1 + 1/2 + 1/3 + ...
I want to calculate the total no of weeks in current month. Starting from
I want to calculate the total data download and upload in a particular interval
i want to to calculate minimum sum in given two dimensional array #include<iostream> #include<limits.h>
In WPF, I want to display sum, average values based on the List of
I want to calculate the total price of a order done by a customer:
I want to calculate the total size of all .mobi files from this link
I want to calculate total physical memory usage of system. This is my code:

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.