#!/bin/bash
cat /home/user/list
read -p "enter a number: " LISTNUMBER
USERNAME=$(awk '$LISTNUMBER {
match($0, $LISTNUMBER); print substr($0, RLENGTH + 2); }' /home/user/list)
echo "you chose $USERNAME."
This script will use awk to search another file that has a list of numbers and usernames:
1 bob
2 fred
etc...
I only want the username not the corresponding number which is why I tried using: print substr($0, RLENGTH + 2)
Unfortunately, the output of the awk won't attach to $USERNAME.
I have attempted to grep
for this but could not achieve the answer. I then read about awk
and got here, but am stuck again. Utilizing grep
or awk
is all the same for me.