0

I'm trying to write a script that will read the country I type in and then display the people who are from that country. It works fine when I write the code with the country I want in, but when I try to use a variable nothing happens. I've been working on this for hours, so could someone please help me. This is what I have so far.

              echo Please choose a country
              echo
              read country


              awk -F: -v theCountry="$country" '

              BEGIN {

              recordCount = 0
              printf "\t\tPlayers from that country\n\n"
              print theCountry
              }

              /theCountry/{

              print $1
              recordCount++


              }

              END {


              }' playerFile

Where I enter theCountry is where it's messing up.

1 Answer 1

2

Change:

/theCountry/{

to:

$0 ~ theCountry {

and read http://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you so much. I am forever in your debt. Thank you for that site, too!
You're welcome. Just click on the "Accepted" check mark next to my answer and we'll call it even ;-).
@EdMorton Users with reputation 1 can not accept answer. They can mark it as useful. But the can come back later when reputation is higher to accept answer :)
@Jotne any user can accept an answer. What users with <15 rep cannot do is to upvote. See privileges.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.