我有一个输入;
8765843279 "dma_code":"501","dma_region";"NEW YORK, NY","check_fpc_cookie":"-1","check_tpc_cookie":"1"
我希望输出为;
8765843279 dma_code 501
8765843279 dma_region NEW YORK, NY
8765843279 check_fpc_cookie -1
8765843279 check_tpc_cookie 1
请有人帮忙吗?
答案 0 :(得分:0)
这可以做到:
$ awk -v RS="," -F"\"" 'NR==1{v=$1}{print v, $2, $4}' file
8765843279 dma_code 501
8765843279 dma_region NEW YORK NY
8765843279 check_fpc_cookie -1
8765843279 check_tpc_cookie 1
它基于this solution by Ed Morton。
RS=","
=>记录以逗号分隔。-F"\""
=>记录中的字段用引号"
分隔。NR==1 {v=$1}
存储第一条记录的值。F="\""
。