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 个解决方案
#1
2
Change:
更改:
/theCountry/{
to:
至:
$0 ~ theCountry {
and read http://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps
并阅读http://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps
#1
2
Change:
更改:
/theCountry/{
to:
至:
$0 ~ theCountry {
and read http://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps
并阅读http://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps