awk - Using bash to search for a string in the second column -
i'm trying write function looks last name (from user input) in second column , returns line user. here i've tried (and not working). importantly, when run last name in place of $input_name @ command line, works then. can see, echo confirm user input read properly. missing?
60 last_search () { 61 echo "what last name looking for?" 62 read input_name 63 echo "$input_name" 64 awk -f':' '$2 ~ /$input_name/{print $0}' temp_phonebook 65 }
- use
-v name=value
pass shell variable awk - shell variable won't expanded in single quote
print $0
default action take out.
you can use:
awk -f: -v input_name="$input_name" '$2 ~ input_name' temp_phonebook
Comments
Post a Comment