[awk] 一行命令處理文字的解析輸出格式OFS
/* 簡潔,推薦 */
grep cpe Recent.xml|grep product |sort|awk -F '<|>' '{ if($3!="") print $3 }'|awk '{print $1,$2,$3,$4}' FS=':' OFS=':'
或 /*通用, 推薦*/
grep cpe Recent.xml|grep product |sort|awk -F '<|>' '{ if($3!="") print $3 }'|awk 'BEGIN{FS=":";OFS=":"} {print $1,$2,$3,$4}'
或 /*蛋略疼*/
$grep cpe Recent.xml|grep product |sort|awk -F '<|>' '{ if($3!="") print $3 }'|awk -F ':' 'BEGIN{OFS=":"} {print $1,$2,$3,$4}'
cat Recent.xml
<vuln:vulnerable-software-list>
<vuln:product>cpe:/a:ca:release_automation:5.5.2</vuln:product>
<vuln:product>cpe:/a:ca:release_automation:6.1.0</vuln:product>
<vuln:product>cpe:/a:ca:release_automation:5.0.2</vuln:product>
<vuln:product>cpe:/a:ca:release_automation:5.5.1</vuln:product>
</vuln:vulnerable-software-list>
References:
https://www.gnu.org/software/gawk/manual/html_node/Output-Separators.html