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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:32:45+00:00 2026-05-27T03:32:45+00:00

I am finding the difference between two columns in a file like cat trace-0-dir2.txt

  • 0

I am finding the difference between two columns in a file like

cat "trace-0-dir2.txt" | awk '{print expr $2-$1}' | sort 

this gives me values like :

-1.28339e+09
-1.28339e+09
-1.28339e+09
-1.28339e+09

I want to avoid the rounding off and want the exact value.How can this be achieved?
FYI ,trace-0-dir2.txt contains:

1283453524.342134 65337.141749 10 2
1283453524.556784 65337.388047 11 2
1283453524.556794 65337.411165 12 2
1283453524.556806 65337.435947 13 2
1283453524.556811 65337.435989 14 2
1283453524.556816 65337.453931 15 2
1283453524.771522 65337.484866 16 2
  • 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-27T03:32:45+00:00Added an answer on May 27, 2026 at 3:32 am

    printf function can help get you the formatting you need. You don’t need expr and you don’t need cat. awk can do any calculation and you can invoke awk directly on the file.

    You can alter the 20.20 to any number based on the format you are looking for.

    [jaypal:~/Temp] cat file0
    1283453524.342134 65337.141749 10 2
    1283453524.556784 65337.388047 11 2
    1283453524.556794 65337.411165 12 2
    1283453524.556806 65337.435947 13 2
    1283453524.556811 65337.435989 14 2
    1283453524.556816 65337.453931 15 2
    1283453524.771522 65337.484866 16 2
    
    [jaypal:~/Temp] awk '{ printf("%20.20f\n", $2-$1)}' file0
    -1283388187.20038509368896484375
    -1283388187.16873693466186523438
    -1283388187.14562892913818359375
    -1283388187.12085914611816406250
    -1283388187.12082219123840332031
    -1283388187.10288500785827636719
    -1283388187.28665614128112792969
    

    From the man page:

    Field Width:

    An optional digit string specifying a field width; if the output string has fewer characters than the field width it will be blank-padded on the left (or right, if the left-adjustment indicator has been given) to make up the field width (note that a leading zero is a flag, but an embedded zero is part of a field width);

    Precision:

    An optional period, `.’, followed by an optional digit string giving a precision which specifies the number of digits to appear after the decimal point, for e and f formats, or the maximum number of characters to be printed from a string; if the digit string is missing, the precision is treated as zero;

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

Sidebar

Related Questions

Can any one help me in finding the basic difference between mutable and immutable?
I am having trouble finding out what the key differences are between the two
I'm trying to determine the score of an entry by finding the difference between
Is it possible to compare two different strings... Finding common words between the two
I'm having a tough time finding the difference between the PHP functions posix_getuid and
Is there an efficiency difference between finding by id and finding by class with
I need to write a C program for finding the differences between two folders,
This query works great for finding the difference between successive rows: select id, created_at,
How do you actually perform datetime operations such as adding date, finding difference, find
a few weeks ago a co-worker of mine spent about two hours finding out

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.