最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

grep - Why don't + and * work when parsing a curl response headers - Stack Overflow

programmeradmin2浏览0评论

I'm trying to use grep to extract a response header from a curl request and for some reason .* and .+ won't match anything but . and ... etc will. It's like the * and + operators just don't work. Example:

curl 'ifconfig.me' -v 2>&1 | grep -Po '< via: \K.+'

Swap . with \w and nothing changes. But

curl 'ifconfig.me' -v 2>&1 | grep -Po '< via: \K.......'

matches something, but not everything. The moment I add * or + to my pattern everything breaks.

Is it because I'm piping stderr to stdout with 2>&1? Is that confusing grep somehow?

I can work around this with curl --write-out '%{header_json}' and extract with jq` but I'm very confused why my first approach didn't work.

发布评论

评论列表(0)

  1. 暂无评论