【发布时间】:2017-07-11 02:03:47
【问题描述】:
我有两个文件:
1. 图案文件 = pattern.txt
2.包含不同术语的文件=terms.txt
pattern.txt 包含两列,以;分隔
在第一列中我有几个术语,在第二列中是缩写,
关联到第一列,同一行。
terms.txt 包含单个单词和由单个单词定义的术语,但也包含
通过单词的组合。
pattern.txt
Berlin;Brln
Barcelona;Barcln
Checkpoint Charly;ChckpntChrl
Friedrichstrasse;Fridrchstr
Hall of Barcelona;HllOfBarcln
Paris;Prs
Yesterday;Ystrdy
terms.txt
Berlin
The Berlinale ended yesterday
Checkpoint Charly is still in Friedrichstrasse
There will be a fiesta in the Hall of Barcelona
Paris is a very nice city
目标是用标准化缩写替换术语并找出哪些术语
没有缩写。
结果我想要两个文件。
第一个文件是一个新的术语文件,术语替换为可以替换的缩写词。
第二个文件包含一个列表,其中包含所有没有缩写的术语。
输出不区分大小写,我不区分“The”和“the”。
new_terms.txt
Brln
The Berlinale ended Ystrdy
ChckpntChrl is still in Fridrchstr
There will be a fiesta in the HllOfBarcln
Prs is a very nice city
terms_without_abbreviations.txt
a
be
Berlinale
city
ended
fiesta
in
is
nice
of
still
The
There
very
will
感谢您的帮助,并提前感谢您的时间和提示!
【问题讨论】:
-
您为自己尝试了什么?在此处发布您的尝试。
-
我每年只使用几次终端,但我不是很有经验。试过 link 但不符合我的情况。
-
您必须记住,如果您发布您的尝试但失败(这不是问题),SO 社区会帮助您,以便我们可以帮助您。人们不能只为您编写免费代码。没有不尊重的意思!
-
因为我非常尊重这个论坛的知识,所以在这里寻求帮助。我尝试了几次,但无法解决问题。提到一次尝试,我可以替换一些术语,问题是我得到的结果只是缩写。
awk -F";" 'NR==FNR{a[$1]=$2;next}{$1=a[$1];}1' pattern.txt terms.txt > new_terms.txt -
好吧,这两个文件中都没有空格会不会很痛苦,即
Checkpoint Charly是Checkpoint-Charly,你可以控制这些文件还是不可能?