Linux 使用AWK或SED和下面的标记用逗号分隔
使用AWK或SED以逗号分隔,并使用以下标记:Linux 使用AWK或SED和下面的标记用逗号分隔,linux,shell,unix,sed,awk,Linux,Shell,Unix,Sed,Awk,使用AWK或SED以逗号分隔,并使用以下标记: [BEGIN AccountID] [BEGIN CallerID] [BEGIN Billed Account Attributes] 1111111 1111111 1111111 [END Billed Account Attributes] [BEGIN OBIO Tax]
[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
....
....
....
当不显示RINO TAX时,用逗号分隔并置零
非常感谢 这可能适合您(GNU-sed):
注意:这会删除空格和空行。到目前为止您尝试了什么?你能和我们分享一些代码或想法吗?如果我们知道您已经了解了哪些内容,就更容易提供帮助。我尝试过:awk'BEGIN{OFS=“;”;}/^[BEGIN AccountID]/{f[nf=0]=$0;而(getline&&$0!~/^[END AccountID]/{f[++nf]=$0;}print f[3],f[15];}'$1关闭!是否可以将每个寄存器放入一个新行?非常感谢波通!!
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