I have a script I'm writing with a file with several names in it (some other info - but it's not really pertinent...) - I want to be allow the user to delete certain records, but I ran into a problem I'm not sure how to go about fixing.
If I were doing this in Java - I would simply say 'record 1 = so-and-so' and 'record 2 = this other guy.' Which one do you want to delete? But how can I do that in a bash script?
A better example:
Who do you want to delete? Nikki
Found 2 Nikki's:
1 - Nikki the Teacher
2 - Nikki the Secretary
Which one to delete?
I am searching the file using nawk '$name' - any suggestions on having the script say 'here's 1 - that's #1, here's another - that's #2 - which one do you want?'
It's Ubuntu - and as for code, there's actually not much at the moment. I've been toying with my other post's code trying to figure something out; but wasn't having much luck.
echo -n "Enter Name to find: "
read name
nawk -F: 'BEGIN{IGNORECASE = 1} /'"$name"'/ {printf "Record found - %s\n", $1}' data
As you can see, it's searches the file by $name and prints out what it found. I've tried a counter in the nawk statement - but that kept coming up with 0 - even when it showed 2 different records found.
And that's where I'm stuck. If I didn't mention it above, this is a bash script.
Thanks for your reply - and sorry about not using code above.
read -p"Who do you want to delete? " NAME
Who do you want to delete? Nikki
select DN in $(grep "$NAME" file) quit; do echo "$DN"; [ "$DN" = "quit" ] && break; done
1) Nikki the Secretary
2) Nikki the Teacher
3) quit