I wrote a small script to manipulate fields of a file based on the input of a user. Is there something I could've done better, or perhaps a better refactor? I do know however that I need a way to validate for empty fields.
view_column() {
for i in "$file_name"; do
cat "$i" | awk -v col="$1" '{ print $col }'
done
}
print_menu() {
menu=( 'First' 'Last' 'Email' 'Exit' )
for (( i=0; i<${#menu[@]}; i++ )); do
printf "%2d. %s\n" "$((i+1))" "${menu[$i]}"
done
}
main() {
while true; do
clear
print_menu
read -p 'Enter a choice: ' choice
if (( "$choice" == 4 )); then
break
fi
view_column "$choice"
sleep 1.5
done
}