在 busybox 中使用選項 -P 進行 Grep

在 busybox 中使用選項 -P 進行 Grep

我想-P在帶有映像的 kubernetes pod 內的 BusyBox v1.31.1 () 多重呼叫二進位檔案中執行帶有選項的 grep 命令curlimages/curl:7.75.0

curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$CFZONE_NAME"\
-H "X-Auth-Email: $CFUSER"\ 
-H "X-Auth-Key: $CFKEY" \
-H "Content-Type: application/json" \
| grep -Po '(?<="id":")[^"]*' \ # <- This is the culprit 
| head -1 
    
curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$CFZONE_ID/dns_records?Name=$CFRECORD_NAME" \
-H "X-Auth-Email: $CFUSER" \
-H "X-Auth-Key: $CFKEY" \
-H "Content-Type: application/json"\
| grep -Po '(?<="id":")[^"]*'\ # <- This is the culprit
| head -1 

不幸的-P是不可用

grep: unrecognized option: P
BusyBox v1.31.1 () multi-call binary.


  Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

        -H      Add 'filename:' prefix
        -h      Do not add 'filename:' prefix
        -n      Add 'line_no:' prefix
        -l      Show only names of files that match
        -L      Show only names of files that don't match
        -c      Show only count of matching lines
[...]


如何解決這個問題?

答案1

可以grep與 一起使用嗎cut

grep -o '"id":"[^"]*' | cut -f4- -d\"

相關內容