如何使用一种模式grep full cdr

时间:2014-12-05 09:41:13

标签: linux

我有一个名为SDPCDR_delsdp5_3037_20141120-201636.ASN的文件,此文件包含以下格式的一些cdr: SDPOUTPUTCDRCP6.SDPCallDataRecord.serviceFeeDeduction

{
    sdpID : "delsdp5a"
    cdrID : "444293"
    originNodeType : "sdp"
    date : "20141120"
    time : "201735"
    accountNumber : "9697356704"
    serviceFeeAmount : "27.638000"
    successCode : 'ok (1)'
    oldServiceClass : '7604'D
    currencyType : '0'D
    servFeeExpDateBefore : "20141019"
    servFeeExpDateAfter : "20141218"
    accountFlags : "10001111"
    balanceAfterDeduction : "29.362000"
    gmtDeviation : "+0530"
    accountGroupID : '0'D
    serviceFeeType : "SUK_150"
    debt : "0.000000"
}

我很喜欢

grep SUK_150 SDPCDR_delsdp5_3037_20141120-201636.ASN
    serviceFeeType : "SUK_150"
so only serviceFeetype type is coming thats k the result will come like that only
but my concern is if any command is there if i grep 
"grep SUK_150 SDPCDR_delsdp5_3037_20141120-201636.ASN"
then full cdr came 

我想输出

coomand-grep SUK_150 SDPCDR_delsdp5_3037_20141120-201636.ASN

结果

SDPOUTPUTCDRCP6.SDPCallDataRecord.serviceFeeDeduction
{
    sdpID : "delsdp5a"
    cdrID : "444293"
    originNodeType : "sdp"
    date : "20141120"
    time : "201735"
    accountNumber : "9697356704"
    serviceFeeAmount : "27.638000"
    successCode : 'ok (1)'
    oldServiceClass : '7604'D
    currencyType : '0'D
    servFeeExpDateBefore : "20141019"
    servFeeExpDateAfter : "20141218"
    accountFlags : "10001111"
    balanceAfterDeduction : "29.362000"
    gmtDeviation : "+0530"
    accountGroupID : '0'D
    serviceFeeType : "SUK_150"
    debt : "0.000000"
}

我想要整个cdr,如果我grep SUK_150

请建议。

1 个答案:

答案 0 :(得分:1)

考虑格式是否固定。

grep -A2 -B18 SUK_150 SDPCDR_delsdp5_3037_20141120-201636.ASN

grep -A:在模式匹配后打印X行 grep -B:在模式匹配之前打印X行