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 } 

  1. use -v name=value pass shell variable awk
  2. shell variable won't expanded in single quote
  3. print $0 default action take out.

you can use:

awk -f: -v input_name="$input_name" '$2 ~ input_name' temp_phonebook 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -