admin管理员组

文章数量:1398780

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.

本文标签: grepWhy don39tand * work when parsing a curl response headersStack Overflow