I have a text file in the following format:
jAY
JAY
JaY
eVAns
Evans
Evans
What I'm trying to do is convert everything to lowercase and then capitalize the first letter of every word. For my script, however, I'm not printing out the correct information.
#!/bin/bash
FILE=names.txt
echo "#################################"
k=1
while read line;do
VAR=$line
VARCAP=$( echo "${VAR}" | tr '[A-Z]' '[a-z]')";
VARCAP1=$( echo "${VARCAP}" | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')
echo "Line # $k: $VARCAP1"
((k++))
done < $FILE
echo "Total number of lines in file: $k"
Everything was working until I added the line to convert all the letters to lowercase - so that is where my problem lies. This is the first bash script I've ever written, so to say I'm green is an understatement.
Any assistance would be appreciated.