neterrore=connectionFailure&u=https%3A//data.com/callback%3Fcode%3DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6_c%26state%3DcDi00NM8gO8BImQwp1G0gmdIznygTwXQ&
在此字符串中,我需要在特定字符串之间提取code%3D
到 c%26state
.
DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6
我需要从给定的该行获取输出。
答案1
假设您需要 code%3D 和 c%26state 之间的字符串,这可能会有所帮助
echo 'neterrore=connectionFailure&u=https%3A//data.com/callback%3Fcode%3DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6_c%26state%3DcDi00NM8gO8BImQwp1G0gmdIznygTwXQ&' | sed 's/.*code%3D\(.*\)c%26state.*/\1/'
答案2
cat /tmp/testfile
"neterrore=connectionFailure&u=https%3A//data.com/callback%3Fcode%3DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6_c%26state%3DcDi00NM8gO8BImQwp1G0gmdIznygTwXQ&" <-- ignore the ""
string=`awk -F% '{print $4}' /tmp/testfile`
O/P:3DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6_c
echo $string| sed 's/^.\(.*\).\{2\}$/\1/'
O/P: DY6mOqlD2Cghcub29IlDKB7KHFuGCemVeoNr1lF5r6