Add a column with % (percentage)

Hello friends,

I have a file2 show below:
file1 - cat file1
John
Tom
file2 - cat file2

Name Count
John 1315
John 509
John 467
John 32
John 27
John 12
Tom 10
Tom 7
Tom 5
Tom 4

I need to add a column to with percentage to the right (below) as file3

Name Count Percent
John 1315 56.0
John 509 21.7
John 467 19.9
John 32 1.4
John 27 1.1
John 12 0.5
Tom 10 38.5
Tom 7 26.9
Tom 5 19.2
Tom 4 15.4

Thanks so much

@bobo
Where exactly are you stuck?
Seems like your posting pattern hasn't changed in at least 3+ years: Add a column to a file - #4 by bobo

Please show your own effort.

1 Like

Hi vgersh99,
I am stuck as I begin. I honestly do not know where to start and I am here to learn.
Many thanks!

Your latest post is from 2021 and oldest is from 2006. I'm sure you have learnt something in the last 18 years.
Give it a try.
I'd suggest looking into parsing your data with awk, and you have multiple threads of your own with provided solutions/hints implemented in awk.

Give it a whirl and do come back showing the effort.

2 Likes

Where do you get the Percent values?

  • From another file?
  • Computed, how?

Thanks for your reply. I created these 2 files for examples. I need the codes in Unix to to get the results in file3.
Many thanks!

@bobo
Please provide more information. Depending on where you get (or intend to get) the third column from, the solution will be different (e.g. one may use paste command to combine already existing columns, the other may use awk to calculate percent values from other existing column(s)). This is community cooperation forum, please show some respect for other people spending time while trying to help you.
Have you tried any of these commands? With what result? Did you read their documentation?