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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:56:28+00:00 2026-06-17T09:56:28+00:00

I a having a sorted file with numeric values like foo 2.3 bar 2.6

  • 0

I a having a sorted file with numeric values like

foo 2.3
bar 2.6
baz 4.7

and would like to have a one-liner which puts the percentile of a line into the last column, like

foo 2.3 0.3333
bar 2.6 0.6666
baz 4.7 1.0000

Thank you.

  • 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-06-17T09:56:29+00:00Added an answer on June 17, 2026 at 9:56 am

    I assume you mean percent of lines, for this you need to know the number of lines first.

    Here’s one way to do it as a two-pass solution with awk:

     awk 'FNR == NR { tot=NR; next } { printf( "%s %.4f\n", $0, FNR/tot) }' file file 
    

    Output:

    foo 2.3 0.3333
    bar 2.6 0.6667
    baz 4.7 1.0000
    

    The first block is only active during FNR == NR i.e. the first pass. The second block takes care of the printing.

    Other alternatives to determine length of file

    Use NR-1 when starting second pass (FNR != NR):

    awk 'FNR != NR { if(!tot) tot=NR-1; printf( "%s %.4f\n", $0, FNR/tot) }' file file
    

    Use wc before running awk:

    awk -v tot=$(wc -l < file) '{ printf( "%s %.4f\n", $0, FNR/tot) }' file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a regular fixed width file that is sorted on one of
Having a sorted list and some random value, I would like to find in
I have data stored in a csv file that looks like this: Date,BLOCK,,Wood,Miscellaneous,,Totals,MO Saturday,4055-RU,4055-AR,4091,1139,1158,,100
I'm having problems reading lines from a text file in PHP. I have this
I have a .txt file which has about 500k entries, each separated by new
I've been having a problem with making sorted lists from dictionaries. I have this
I would like to have a playlist for my own music player in Delphi
I have one very large text file(27GB) that I am attempting to make smaller
I have the following data that looks like this for example: 34 foo 34
Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase

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.