我正在看一些 comments ,并试图决定最适合购买苹果的公司(例如).我复制并粘贴了下面的文本,我想用Linux命令对其进行一些文本处理.从我在网上读到的内容来看,awk是一个很好的 Select ,但我无法让它工作.
我try 取下有评级的行,并用逗号分隔将其附加到上面的行.例如:Abes Apples\n 4.1
将变成Abes Apples, 4.1
,并重复此过程.我测试的awk命令是awk 'BEGIN {RS=""}{gsub(/\n[0-9]/, ", ", $0); print $0}' test.text
,它给出了下面的结果,但它正在替换数字.
Abes Apples, .1,
(138) · apple company, + years in business (123) 456-7890
Adams Apples, .9,
(105) · apple company, 0+ years in business (234) 567-8901
Apples are Amazing, .9,
(13) apple company, 0+ years in business (345) 678-9012
文本文件模式如下所示,并对文本文件中的所有行重复:
- 公司名称
- 额定值
- comments 数量和公司类型
- 营业年限和电话号码
我的目标是将这个文本文件转换成类似CSV的格式,其中我有公司名称、评级、 comments 数量(忽略‘Apple Company’文本)、经营年限和电话号码的列标题.这是否可以使用awk和其他Linux命令来完成?
Current Input:个
Abes Apples
4.1,
(138) · apple company
7+ years in business (123) 456-7890
Adams Apples
4.9,
(105) · apple company
10+ years in business (234) 567-8901
Apples are Amazing
3.9,
(13) apple company
10+ years in business (345) 678-9012
Desired Output:个
Abes Apples, 4.1,(138), 7, (123) 456-7890
Adams Apples, 4.9, (105), 10, (234) 567-8901
Apples are Amazing, 3.9, (13), 10, (345) 678-9012