源文件
<?xml version="1.0" encoding="UTF-8" ?>
<result>
<lrc id="123" artist="linkin park" title="In the end"></lrc>
<lrc id="456" artist="arvil" title="thing's you never know"></lrc>
</result> |
<?xml version="1.0" encoding="UTF-8" ?>
<result>
<lrc id="123" artist="linkin park" title="In the end"></lrc>
<lrc id="456" artist="arvil" title="thing's you never know"></lrc>
</result>
——————— 格式化输出文件 ID: 123 artist: linkin park title In the end ID: 456 artist: arvil title thing’s you never know ——————— 文本过滤的shell脚本(写的很实用)
#!/bin/bash
XML_FILE_NAME=$1
grep "lrc" ${XML_FILE_NAME} | cut -d '"' -f 2,4,6 | awk 'BEGIN {FS="\""} {id[NR]=$1;artist[NR]=$2;title[NR]=$3}END {for (i=1;i<NF;i++) print "ID: " id[i]"\tartist: " artist[i]"\ttitle" title[i]}' |
#!/bin/bash
XML_FILE_NAME=$1
grep "lrc" ${XML_FILE_NAME} | cut -d '"' -f 2,4,6 | awk 'BEGIN {FS="\""} {id[NR]=$1;artist[NR]=$2;title[NR]=$3}END {for (i=1;i<NF;i++) print "ID: " id[i]"\tartist: " artist[i]"\ttitle" title[i]}'