#!/bin/bash input="input.txt" word_count(){ file="$1" awk 'NF { gsub(/[[:space:]]+$/, ""); word = tolower($0); word = toupper(substr(word, 1, 1)) substr(word, 2); print word }' "$file" | sort | uniq -c | awk '{ printf "%-10s %d\n", $2, $1 }' } echo "Do you want to count existing words in $input? (y/n): " read choice if [ $choice == "y" ] then echo "Counting existing words..." word_count "$input" elif [ $choice == "n" ] then touch newinput.txt newitems="newinput.txt" echo "How many items do you want to add? " read num_items for (( i=0; i> "$newitems" done echo "New items added. Counting words..." word_count "$newitems" fi > "$newitems"