shell—在unix中将多行转换为单行

zbdgwd5y  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(408)

我有一个文件,其中有多行数据在一列,我想多行转换为单行。
这是带有标题的示例

final_date|Notes|Status
04/17/2019|"- OB Team - 
Number of Attempt(s): 1
Outcome:other
Order (RMO):0
Campaign : ABC
Additional Notes:  not a working number  

* If any call return to transfer to OB team *"|Complete

04/18/2019|"- OB Team - 

Number of Attempt(s): 3
Outcome: NO ANSWER
Order (RMO): 0
Campaign Name: ABC

* If return call, transfer to OB team*

- OB TEAM - 
Number of Attempt(s):  1 
Outcome:  VM
Order (RMO):  0
Campaign Name:  ABC 
Additional Notes: None

* If return call, transfer to OB team*"|Complete

以上数据有两条记录。我希望它们转换为单行,然后加载到配置单元表。
以上数据应按以下方式转换。

final_date|Notes|Status
04/17/2019|"- OB Team - Number of Attempt(s): 1 Outcome:other Order (RMO):0 Campaign : ABC Additional Notes:  not a working number * If any call return to transfer to OB team *"|Complete
04/18/2019|"- OB Team - Number of Attempt(s): 3 Outcome: NO ANSWER Order (RMO): 0 Campaign Name: ABC *If return call, transfer to OB team*  - OB TEAM - Number of Attempt(s):  1  Outcome:  VM Order (RMO):  0 Campaign Name:  ABC Additional Notes: None *If return call, transfer to OB team*"|Complete

有人能帮我一下吗。

kx1ctssn

kx1ctssn1#

根据当前行中双引号的数目操作输出记录分隔符。

awk -F\" 'BEGIN{ors=ORS} NF&&!(NF%2){ORS=(ORS!=ors)?ors:OFS} 1' file

相关问题