使用grep在bash中获取Set-Cookie头中的数据

问题描述 投票:0回答:1

我有这样的字符串

SCNT:AAAA + jMzRkQ2NjZGMTU5OTQ4NjcxQTA4OUE0MDk2RUYwRkQwMkU0OERFQjcxRkNFQUE5QzgxRUNFMkY5NzI3QjBFMjNGNTk1MTMyNjg3NDIyMkFBQzVFREJDNzdBNkI4RDNGNzVDMzVCMjIzMDNDNjhBODgzODhDOTFFNzIyNDkzMEY1RjZEQTQ0Mjc3NDYyQzJCNjI3Qjc3RTQ1Mjc2QTU2NzdCNEVCQTAwNTdFQ0Q0ODcxMDkyRUQ4OTJDNUJBNEYyNjk4NTE5NUQxMzlFQjFCMEFFRjZGODM2ODUxQkU2MEY3RDkzQTFGQUY5N0ZCRjg2NXwxAAABYG1QuD47akz0XdTR / c2RN1Q + RHpX2shK2V9u476rlbhG / c8f72E / Z5TaFIDuA的Set-Cookie:aidsp = 33FD666F159948671A089A4096EF0FD02E48DEB71FCEAA9C81ECE2F9727B0E23F5951326874222AAC5EDBC77A6B8D3F75C35B22303C68A88388C91E7224930F5F6DA44277462C2B627B77E45276A5677B4EBA0057ECD4871092ED892C5BA4F26985195D139EB1B0AEF6F836851BE6;

我想把它之间的字符串

Set-Cookie:aidsp = thisstring;

我用这个命令试了一下

sessionID="$(echo "$resp" | awk -F[=";"] '{print $2}')"

但这不起作用。

bash
1个回答
0
投票

使用grep和积极的lookbehind:

sessionID="$(echo "$resp" | grep -oP '(?<=Set-Cookie: aidsp=)[0-9A-F]*')"
© www.soinside.com 2019 - 2024. All rights reserved.