通过使用逗号分隔的AWK或者与下面的标签SED(Delimited by comma using A

2019-07-30 09:46发布

通过使用逗号分隔AWK或低于所用标签SED:

[BEGIN AccountID]
        [BEGIN CallerID]
            [BEGIN Billed Account Attributes]
            1111111
            1111111
            1111111
            [END Billed Account Attributes]

        [BEGIN OBIO Tax]
        10
        20
        30
        [END OBIO Tax]

        [BEGIN RINO Tax]
        777
        888
        999
        [END RINO Tax]
    [BEGIN CallerID]
[END AccountID]


[BEGIN AccountID]
    [BEGIN CallerID]
        [BEGIN Billed Account Attributes]
        2222222
        2222222
        2222222
        [END Billed Account Attributes]

        [BEGIN OBIO Tax]
        40
        50
        60
        [END OBIO Tax]

    [BEGIN CallerID]
[END AccountID]

我想一个AWK或sed脚本打印此:

1111111,1111111,1111111,  10,20,30,  777,888,999

2222222,2222222,2222222,  40,50,60,    0,  0,  0
....
....
....

以逗号分隔,并把ZERO时,不会显示RINO税。

非常感谢!!!!

Answer 1:

这可能会为你工作(GNU SED):

sed '/\[BEGIN AccountID\]/,/\[END AccountID\]/!d;/\[BEGIN AccountID\]/{h;d};/./H;/\[END AccountID\]/!d;g;s/\n*\[[^\n]*\n*//g;s/\n/,/g;s/\s*//g;ta;:a;s/,//9;t;s/$/0,0,0/' file

注意这将删除空格和空行。



文章来源: Delimited by comma using AWK or SED with the tags below