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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:31:54+00:00 2026-05-13T06:31:54+00:00

Now my program generates two data files. a.txt and b.txt Take a.txt as an

  • 0

Now my program generates two data files. a.txt and b.txt
Take a.txt as an example, it’s content just like this:

0,0
0,1
1,0
-3,1
1,-2
1,3
......

b.txt is similar with a.txt.

Now, I hope to find out average distance between the corresponding content in a and b file.
In other words, for example, if b.txt like this:

0,0
1,1
1,2
-3,1
1,-2
1,3
......

Then the distance is calculated in this way:

  sqrt[square(0-0)+square(0-0)]
    +sqrt[square(0-1)+square(1-1)]
    +sqrt[square(1-1)+square(0-2)]
    +sqrt[square((-3)-(-3))+square(1-1)]
    +sqrt[square(1-1)+square((-2)-(-2))]
    .......
   _____________
   /Total number(i.e 10,000)

to get the average distance between these two files content.

Question: how to write a shell script which can carry out the calculation process like above? And output the final average distance?

Hint: you may view two groups of coordinates are stored in two files.

Need your kind help..Many many Thanks.

Addition:
There are about 10,000 – 100,000 rows for each files.

  • 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-13T06:31:55+00:00Added an answer on May 13, 2026 at 6:31 am

    AWK is really good for doing simple mathematical calculations on files containing rows of delimited data. There is a very good AWK guide here: http://www.vectorsite.net/tsawk.html

    A general structure for this program could be:

    Store the first row
    For each additional row, calculate the distance between it and the last row and overwrite the stored values
    Add the distance to a variable containing the distance sum
    Divide at the end by the number of rows seen (conveniently stored for you by AWK)
    Output the result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My program is now still running to import data from a log file into
The program I'm coding now makes a pretty huge list of data items. Now,
I have a program that generates reports by using DataTables created by TableAdapters. Now
I signed up for the iPhone Developer Program (now awaiting approval) using a new
Im working right now on a program that can divide, add, ect, but, im
I am currently coding some chat program and now want to play music via
We had our own custom logger in a C# program and now are trying
Now I wanna develope a windows service console program via WPF. Each service is
Right now I am writing a program in OpenGl. I'm rendering some-what complex 3D
I now have a running Java program which only lacks of the final step,that

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.