【发布时间】:2016-02-09 05:42:21
【问题描述】:
我有几个由不同人制作的大型文本文件。这些文件包含每行单个标题的列表。每个句子都是不同的,但据说是指相同的 - 未知 - 一组项目。
鉴于格式和措辞不同,我尝试生成一个较短的文件,其中包含可能的匹配项以供手动检查。我是 Bash 的新手,我尝试了几个命令来将每一行与具有两个或多个共同关键词的标题进行比较。应避免区分大小写,超过 4 个字符的关键字应排除文章等。
例子:
输入文本文件#1
Investigating Amusing King : Expl and/in the Proletariat
Managing Self-Confident Legacy: The Harlem Renaissance and/in the Abject
Inventing Sarcastic Silence: The Harlem Renaissance and/in the Invader
Inventing Random Ethos: The Harlem Renaissance and/in the Marginalized
Loss: Supplementing Transgressive Production and Assimilation
输入文本文件#2
Loss: Judging Foolhardy Historicism and Homosexuality
Loss: Developping Homophobic Textuality and Outrage
Loss: Supplement of transgressive production
Loss: Questioning Diligent Verbiage and Mythos
Me Against You: Transgressing Easygoing Materialism and Dialectic
输出文本文件
File #1-->Loss: Supplementing Transgressive Production and Assimilation
File #2-->Loss: Supplement of transgressive production
到目前为止,我已经能够清除一些具有完全相同条目的重复项...
cat FILE_num*.txt | sort | uniq -d > berbatim_duplicates.txt
...以及其他一些在括号中具有相同注释的人
cat FILE_num*.txt | sort | cut -d "{" -f2 | cut -d "}" -f1 | uniq -d > same_annotations.txt
一个看起来很有前途的命令是用正则表达式找到的,但我没能让它工作。
提前致谢。
【问题讨论】:
-
我认为这个问题不太适合
bash- 当然不是单行!考虑使用 Python 之类的脚本语言,这样您就可以更轻松地跟踪每个文件中的行。 -
好的,你能不能给我一个例子或一些开始的指示。谢谢
-
必须有两个共同的关键词,但在你的例子中“Supplement”=="Supplementing"
-
@Labo 我认为常用词是
Transgressive和Production。 -
如果关键字
Transgressive和Production不止一行怎么办?