gpt4 book ai didi

bash - awk 或其他命令如何获取字符串 curl 结果的变量值?

转载 作者:行者123 更新时间:2023-12-04 19:00:03 27 4
gpt4 key购买 nike

在 bash 脚本中,我正在为获取数据的 POST 请求运行 curl

f_curl_get_data (){

read -p "start date : " start_date
read -p "end date : " end_date

# (!) NOTE
# - the date time format must be YYYY-MM-DD

mng_type=users
user=myuser
secret=mysecret

curl --location --request POST 'https://myapi.com/api/v2.1/rest/exports' \
--header 'Content-Type: application/json' \
--header 'SDK-APP-ID: '$user'' \
--header 'SDK-SECRET: '$secret'' \
--data-raw '{
"type":"'$mng_type'",
"start_date":"'$start_date'",
"end_date": "'$end_date'"
}'

}

我得到以下结果
{"results":{"created_at":"2020-03-13T07:04:14Z","download_url":"","error_message":"","original_filename":"2020-03-13T07:04:14Z_exported_users.json","percentage":0,"resource_name":"users","size":0,"status":"started","total_rows":0,"unique_id":"37c23e60-5b83-404a-bd1f-6733ef04463b"},"status":200}

如何使用 awk 命令或其他命令从变量“unique_id”中获取值?
37c23e60-5b83-404a-bd1f-6733ef04463b

感谢你

最佳答案

使用 sed

sed -e 's/.*unique_id":"\(.*\)\"}.*/\1/'

演示:
:>echo '{"results":{"created_at":"2020-03-13T07:04:14Z","download_url":"","error_message":"","original_filename":"2020-03-13T07:04:14Z_exported_users.json","percentage":0,"resource_name":"users","size":0,"status":"started","total_rows":0,"unique_id":"37c23e60-5b83-404a-bd1f-6733ef04463b"},"status":200}' | sed -e 's/.*unique_id":"\(.*\)\"}.*/\1/'
37c23e60-5b83-404a-bd1f-6733ef04463b


关于bash - awk 或其他命令如何获取字符串 curl 结果的变量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60666719/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com