Category Depth Size Words
entity#n#1 0 3037 acetum:dwelling:class_taxopsida:genus_salamandra:vascular_ray
abstraction#n#6 1 2373 expletive:family_hypericaceae:sound_law:scansion
我有一个tsv文件包含许多行,如上所述。我想使用shell脚本创建一个.csv文件,如下所示:
Category Word
entity#n#1 acetum
entity#n#1 dwelling
entity#n#1 class_taxopsida
...
abstraction#n#6 expletive
abstraction#n#6 family_hypericaceae
...
我将如何做到这一点?
答案 0 :(得分:1)
使用awk的分割功能:
awk '{split($4, a, ":"); for (i=1; i<=length(a); i++) print $1, a[i]}' OFS="\t" file
Category Words
entity#n#1 acetum
entity#n#1 dwelling
entity#n#1 class_taxopsida
entity#n#1 genus_salamandra
entity#n#1 vascular_ray
abstraction#n#6 expletive
abstraction#n#6 family_hypericaceae
abstraction#n#6 sound_law
abstraction#n#6 scansion