Using XML starlet to pull values

纵然是瞬间 提交于 2020-01-06 21:42:53

问题


Given:

 <UOIS UOI_ID="9352923211a63c6fe6643832d3c4a7786e21ed26" CONTENT_TYPE="VIDEO" NAME="TR2014_295_11_1a_PM.mov" VERSION="1" METADATA_STATE_DT="2016-06-03 17:01:10.0" METADATA_STATE_USER_ID="1" IMPORT_DT="2016-06-03 13:35:58.0" IMPORT_USER_ID="1" MASTER_OBJ_MIME_TYPE="video/quicktime" MODEL_ID="30001">
 <FILE_SIZE_VIEW CONTENT_SIZE="100948.92       " />
 <SI_AV_ASSET_METADATA VIDEO_BIT_RATE="226 Mbps" REGIONAL_ENCODING_FORMAT="NTSC" DC_TITLE="TR2014_295_11_1a_PM.mov" VIDEO_ORIGINATION_FORMAT="Betacam SP" AV_ASSET_TYPE="Video - Original" MODIFICATION="Editing Allowed" />
 <SI_AUDIO_LANGUAGE_DTLS LANGUAGE="English" />
 <SI_ASSET_METADATA HOT_FOLDER_IMPORT_ID="23335" PUBLIC_USE="No" PRIMARY_CREATOR="Bl" CAPTURE_DEVICE="Captured via Sony DVW-A500 Digital Betacam VTR, SDI to Blackmagic UltraStudio Express ADC to Blackmagic Media Express software" IS_RESTRICTED="No" OWNING_UNIT_UNIQUE_NAME="NMAAHC-TR2014_295_11_1a_PM" ALTERNATE_IDENTIFIER_1="TR2014.295" COLOR_SPACE="YCbCr " EMBARGO="No" />
 </UOIS>

How do I pull the values for UOI_ID and OWNING_UNIT_UNIQUE_NAME? How to pull attributes from different tags and concat them is the basic question.


回答1:


Assuming that SI_ASSET_METADATA is direct child of UOIS (currently, it isn't clear since UOIS element isn't closed) :

xmlstarlet sel -t -m "//UOIS" \
        -v "concat(@UOI_ID, ', ' , SI_ASSET_METADATA/@OWNING_UNIT_UNIQUE_NAME)" \
        -n your_xml.xml


来源:https://stackoverflow.com/questions/43216296/using-xml-starlet-to-pull-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!