입력하다
<acc_details acct_no="00000" acct_nm="John"/>
<acc_details acct_no="00001" acct_address="109 BIRHN WAY " acct_nm="BARNS WY"/>
<acc_details acct_no="00002" acct_nm="BILL BAR" phne_nm="123456"/>
예상 출력
acct_no,acct_address,acct_nm,phne_nm
00000,,John,
00001,109 BIRHN WAY,BARNS WY,
00002,,BILL BAR,123456
답변1
xml
루트 태그를 추가하여 파일을 복구합니다.
<accounts>
<acc_details acct_no="00000" acct_nm="John"/>
<acc_details acct_no="00001" acct_address="109 BIRHN WAY " acct_nm="BARNS WY"/>
<acc_details acct_no="00002" acct_nm="BILL BAR" phne_nm="123456"/>
</accounts>
그런 다음 xml
파서를 사용하여예를 들어xmlstarlet
:
{
echo "acct_no,acct_address,acct_nm,phne_nm"
xmlstarlet sel -t \
-m '//acc_details' \
-v "concat(@acct_no,',',@acct_address,',',@acct_nm,',',@phne_nm)" -n \
input_file
}
산출:
acct_no,acct_address,acct_nm,phne_nm
00000,,John,
00001,109 BIRHN WAY ,BARNS WY,
00002,,BILL BAR,123456