I am trying to print a sum in the middle of a line. My script prompts for a user name and then pulls a total number of processes and a total of time for that user from a file. I want to print a sentence with the totals in the middle of the sentence.Using awk I can get the totals  for processes and minutes but am unable to print the results of an equation in the middle of a sentence. My equation's result shows up after the sentence. I feel like I need to use an anchor like in HTML. I am using PuTTY.   oliver|Login|100 smith|Login|20 oliver|Time|25 oliver|Time|25 smith|Time|20 Anne|Login|100Example: User name? oliveroliver has run 3 processes for a total of 150 minutes case $choice in   1) echo -n User name?    read username    echo $username has run processes for a total of minutes    ;;I would like to get a total for processes and minutes for the specific user name entered. Then insert those numbers into the sentence where they belong.
How to enter a sum derived from awk in the middle of text output
shell script;text processing;awk;scripting
The following script takes its args from the command line rather than a prompt.  This makes it easier to re-use from other scripts and allows the user to specify multiple usernames.$ cat jake.sh #! /bin/shinputfile='input.txt'for u in $@ ; do    awk -F'|' -v u=$u '$1 == u { sum = sum + $3 ; count++}         END {print u  has run  count  processes for a total of  \             sum  minutes.}' < $inputfiledoneNote how the shell script passes the shell variable $u to the awk script via the -v u=$u option.  That avoids having to use double-quotes around the awk script to use the shell $u directly...as that would require escaping every instance of $1, $3, and every  in the awk script with a backslash \.The input is same as in your example:$ cat input.txt oliver|Login|100smith|Login|20oliver|Time|25oliver|Time|25smith|Time|20Anne|Login|100And here's the output:$ ./jake.sh oliver smith Anneoliver has run 3 processes for a total of 150 minutes.smith has run 2 processes for a total of 40 minutes.Anne has run 1 processes for a total of 100 minutes.If you really wanted it to prompt for the username, the script would look like this:#! /bin/shinputfile='input.txt'echo -n User name?read usernameawk -F'|' -v u=$username '$1 == u { sum = sum + $3 ; count++}     END {print u  has run  count  processes for a total of  \         sum  minutes.}' < $inputfile