0

Suppose we have a log file like marks.log and the content looks something like this:

Fname   Lname   Net Algo    
Jack    Miller  15  20  
John    Compton 12  20  
Susan   Wilson  13  19  

I want to add a new column that contains average for each person (row), and a new row that contains average for each course (column). I'm new to bash can i can't figure the syntax for loops and awk etc.

2
  • I've tried awk command that calculates average on each column easily. awk '{ total += $2; count++ } END { print total/count }' marks.log But I can't make it to work in a loop, so I have to write an awk command for each column. And I can't calculate average on rows. – user1859201 Oct 3 '15 at 9:26
  • 1
    Why not convert it to CSV, and use Numbers? It'll be simpler to do if you have no experience with Bash. Also to add to @patrix, add what you've tried to the question, and the results you received. May I also suggest FISH as your designated shell, it's more Friendly, and Interactive. Less intimidating for less experienced users. – user14492 Oct 3 '15 at 9:28
1

Based on what you did so far:

awk '{count++; col2 += $2; col3 += $3; print ($2+$3)/2}
     {END print col2/count, col3/count}' marks.log

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .