0

I have a file named input.txt which contains students data in StudentName # ClassName #SchoolName # Subject1Marks # Subject2Marks format.

Shriii#First#ADCET#95#90
Chaitraliii#Second#ADCET#80#75
Shubhangi#First#ADCET#75#70
Tushar#Second#RIT#80#79
Prathamesh#First#RIT#88#63

The output should contains record of students whose average is more than 90. I have to show the average in new column.

The expected output is Shriii|First|ADCET|95|90|92.5 I tried various ways but was not able to generate expected output. I tried Link1 Link2

SMshrimant
  • 638
  • 9
  • 15
  • 1
    What did you learn from those questions? Did you understand the code you tried? What questions do you have about it (aside from "Can someone do this for me?") – glenn jackman Feb 22 '19 at 00:42

1 Answers1

1

awk to the rescue!

$ awk -F# -v OFS='|' '{$(NF+1)=($(NF-1)+$NF)/2}1' file

Shriii|First|ADCET|95|90|92.5
Chaitraliii|Second|ADCET|80|75|77.5
Shubhangi|First|ADCET|75|70|72.5
Tushar|Second|RIT|80|79|79.5
Prathamesh|First|RIT|88|63|75.5
Sukrut|Second|KIT|91|90|90.5

or pipe to column to get pretty output

... | column -ts'|'

Shriii       First   ADCET  95  90  92.5
Chaitraliii  Second  ADCET  80  75  77.5
Shubhangi    First   ADCET  75  70  72.5
Tushar       Second  RIT    80  79  79.5
Prathamesh   First   RIT    88  63  75.5
Sukrut       Second  KIT    91  90  90.5
karakfa
  • 66,216
  • 7
  • 41
  • 56