#!/bin/sh
# Script to count the total in an array
# Define the name of the file
#
fname=names.txt
# Read in the contact details from the keyboard
echo "Please enter the following contact details:"
echo
echo "Given name: \c"
read name
echo " value: \c"
read value
# Write the details to the text file
echo $name:$value >> $fname
I'm trying to code something in bash scripting, I have a txt file and I entered the following names on it e.g
lex +7.5
creg +5.3
xondr/xonde +1.5
gloria-1
lex +7.5
gloria -1
creg +5.3
xondr/xonde +1.5
lex +7.5
#and so on
I want a code or a loop that when I run the program it should show the names of that are on the txt file and show there total,if lex appears 7 times and gloria 3 times it will show lex 52.5 gloria-3 etc. I don't know if you get my idea...
It sounds like you want something like:
$ awk '{x[$1] += $2} END {for( i in x) print i, x[i]}' input-file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With