我有以下要操作的文本文件
add_journal_volume group="RPCG_VLS_PSALTUXP201" copy="TW_PROD_VLS" uid="60,06,01,60,01,d0,40,00,37,1e,85,5e,17,9c,ea,11" uid_hash="0xfd81565b74f160c3" -f;
add_replication_volume group="RPCG_VLS_PSALTUXP201" copy="VNX057_CRR_PSALTUXP201" replication_set="RSet0" uid="60,06,01,60,0e,60,3c,00,16,f5,56,7f,02,d8,e8,11" uid_hash="0xd7c77496f2520fbc" -f;
add_replication_volume group="RPCG_VLS_PSALTUXP201" copy="VNX057_CRR_PSALTUXP201" replication_set="RSet1" uid="60,06,01,60,0e,60,3c,00,18,f5,56,7f,02,d8,e8,11" uid_hash="0x62d865f2be9ff409" -f;
基本上我只想使用“;”作为列分隔文本返回
RPCG_VLS_PSALTUXP201;TW_PROD_VLS;;60,06,01,60,01,d0,40,00,37,1e,85,5e,17,9c,ea,11
RPCG_VLS_PSALTUXP201;VNX057_CRR_PSALTUXP201;RSet0;60,06,01,60,0e,60,3c,00,16,f5,56,7f,02,d8,e8,11
RPCG_VLS_PSALTUXP201;VNX057_CRR_PSALTUXP201;RSet1;60,06,01,60,0e,60,3c,00,18,f5,56,7f,02,d8,e8,11
棘手的部分是那些add_journal_volume
行没有,replication_set
所以在这种情况下我只想将其留空。
答案1
和perl
:
perl -lne 'my %f; $f{$1} = $2 while /(\w+)="(.*?)"/g;
print join ";", @f{qw(group copy replication_set uid uid_hash)}'