【发布时间】:2018-06-30 16:19:11
【问题描述】:
我试过的是
read -p "Enter City In Australia: " city
function getaa {
curl -s http://localhost:8080/api/examples-services/postcode/$city/ |
json_pp | grep -E '"' | cut -d \ -f7-30 | cut -d: -f1 | tr -d '"' |
sed '1d'
}
getaa
#read -p "Enter City In Zip :" sub
#curl -s http://localhost:8080/api/examples-services/postcode/$city/ | json_pp | grep -E '"' | cut -d \ -f7-30 | cut -d: -f2 | tr -d '",,,' | sed '1d' | sed -n ${sub}p
而且在我进入一个城市后,我想输出他们的邮政编码
我目前的输出是:
Perth
Perthville
Perth Gpo
North Perth
Perth East
我的预期输出是:
1.Perth
2.Perthville
3.Perth Gpo
4.North Perth
5.Perth East
【问题讨论】:
-
为什么不保留一个计数器并输出每个输入城市的当前计数,然后将计数增加
1? -
@DavidC.Rankin 先生怎么样?
-
就简单计数而言,就在您的
read上方的declare -i count=0某处。然后作为getaa的第一行添加printf "%d." $((count++))。每次调用getaa,都会在第一个城市之前输出1.,然后在第二个城市之前输出2.,以此类推。 -
@IanJayloGuinto,请在您的帖子中使用 CODE TAGS 发布任何 curl 命令左右的输出,cmets 不适合这样做。
-
将
-w增加到您需要的任意位数。 (例如-w 3for0-999)您可以在nl(1) - Linux man page查看所有选项