【发布时间】:2019-09-10 16:29:09
【问题描述】:
我有一个 CSV 文件,我需要从中生成一个包含新行的新文件。我在 Bash 和 Python 方面有一些经验。
例子:
Source
Country A,Place1;Place2;Place3,Other info
Country B,Place4;Place5;Place6,Other stuff
Country C,Place7;Place8;Place9,Other examples
Target
Place1,Country A,Other info
Place2,Country A,Other info
Place3,Country A,Other info
Place4,Country B,Other stuff
Place5,Country B,Other stuff
Place6,Country B,Other stuff
所以我需要用; 分隔符分割第二列,并根据行中的其余信息创建一个新行。
【问题讨论】:
-
awk非常适合解决这个问题。花时间处理Awk Tutorial 的相关部分,尤其是split()函数和for循环。然后编辑您的 Q 以显示您解决问题的最佳尝试。包括您当前的输出和任何错误消息(确切地说,复制/粘贴)。祝你好运。 -
感谢您的回复。我在工作中处于通常的情况,昨天有人需要这个,我一直在四处挖掘并使用 awk , sed 等进行测试,但无济于事。