I have sorted (descending) output in a file in table format from a query I did using aws CLI. I need to take a field from the output file and present all unique lines as an option for user to choose from. Here is an example of output file:
Description Snapshot StartTime
Volume0 snap-x123456789 2020-04-22T20:55:10
Volume10 snap-y123456789 2020-04-22T20:45:09
Volume12 snap-a123456789 2020-04-22T20:40:08
Volume15 snap-b123456789 2020-04-22T20:35:07
Volume0 snap-c123456789 2020-04-22T20:30:06
Volume10 snap-d123456789 2020-04-22T20:25:05
The goal is to present all volumes after reading above output and prompt user to enter volume number OR user can enter A for ALL so that system can restore the snapshot(s) for that volume. Something like this:
0 - Volume0
10 - Volume10
12 - Volume12
15 - Volume15
Here is what I have, how can I get the user to enter a number corresponding to the volume number or enter ALL to restore all? Should I be using an array for from the output file? How can I do this efficently?
output() {
echo "Here is a list of volumes found in $region"
for DR in (grep Volume# "$input" | top -n 1)
do
echo $DR
done
echo "Hello, please tell me what Volume you are searching for..(Volume?):"
read volSearch
echo -e "Searching for newest SnapshotIds in region using output file GetfileSnapId for:\n" $volSearch
echo
sleep 5
input="/Users/user/Downloads/GetfileSnapId"
if x=$(grep -m 1 "$volSearch" "$input")
then
echo
echo "$x"
else
echo
echo "$volSearch not found..ending search"
fi
extractSnap=$(echo "$x" | cut -d'|' -f2 )
echo
echo $extractSnap
regionoutput=$(echo "$extractSnap" | awk '{print $4}' )
echo
echo "$regionoutput"
}