Skip to main content
1 of 3
John1024
  • 76.4k
  • 12
  • 176
  • 165

Let's take this as a sample input file:

$ cat file
jim|process1|23
bob|process2|5
jim|process3|7

Now, let's create this shell script:

$ cat script.sh
read -p "Please Enter a UserName: " uname
awk -v n="$uname" -F\| '$1==n{total+=$3} END{printf "Total for %s is %s minutes\n",n,total}' file

As an example, let's sum up the time used by jim:

$ bash script.sh
Please Enter a UserName: jim
Total for jim is 30 minutes
John1024
  • 76.4k
  • 12
  • 176
  • 165