如何从特定字符串开始一行格式化以特定字符串结束

时间:2014-10-17 06:35:32

标签: grep

我想grep" [calleruid] = aab01b055-89e3-49f3-839e-507bb128d07e& smscresponse" 在下面的文件

2014-10-15 18:38:32,831 plivo-rest[2781]: INFO: Fetching GET http://*******/outbound_callback.aspx with smscresponse[to]=8912722fsf9&smscresponse[ALegUUID]=5bb516fsd64-546c-11e4-879f-551816a551303677&smscresponse[calluid]=aab01b055-89e3-49f3-839e-507bb128d07e&smscresponse[direction]=outbosund&smscresfdsponse[endreason]=UNALLOCATED_NUMBER&smscresponse[from]=83339995896999&smscresponse[starttime]=0&smscresponse[ALegRequestUUID]=5bb4bafc-546c-11e4-891d-000c29ec6e41&smscresponse[RequestUUID]=5bb4bafc-546c-11e4-891d-000c29ec6e41&smscresponse[callstatus]=completed&smscresponse[endtime]=1413378509&smscresponse[ScheduledHangupId]=5bb4c15a-546c-11e4-891d-000c29ec6e41&smscresponse[event]=missed_call_hangup

我使用了这个命令

$ grep -oP '(calluid).*$'

这个greps到文件末尾

我使用了这个命令

$ grep -oP '(calluid).{40}'

它可以获取40个字符,但我有1000个字符,所以每个字符都有不同的字符

所以请指导我grep确切的callerid数据

2 个答案:

答案 0 :(得分:0)

使用前瞻来强制正则表达式引擎执行与特定字符或边界的匹配。

$ grep -oP '\[calluid\][^\]\[]*(?=\[|$)' file
[calluid]=aab01b055-89e3-49f3-839e-507bb128d07e&smscresponse

答案 1 :(得分:0)

这是gnu awk(由于RS中的多个字符)版本:

awk -v RS="[[]calluid[]]=" -F[ 'NR==2 {print $1}' file
aab01b055-89e3-49f3-839e-507bb128d07e&smscresponse

您也可以像这样设置RS:RS="\\\[calluid]="

相关问题