从bash中的两个不同文件输出不同的单词

问题描述 投票:0回答:1

我有两个文件,一个文件中充满了错误、大写字母和标点符号,另一个文件包含字典中的所有单词。我需要将所有拼写错误的单词输出到一个新文件中。

我尝试了 diff、comm 和 cmp、grep 和 vim,但它一直返回错误的输出。

假设文件文本包含:

A discreption of a task to do.

字典包含:

a
description 
of
task
to
do

错误的输出应该是单词 disreception,甚至可能是单词 do。因为它的末尾有一个点。

到目前为止,将每个单词都变成小写,并将它们全部放在不同的行上:

tr '[:upper:]' '[:lower:]' < text > textlowercase
tr -s ' ' '\n' < textlowercase > textlowercase

有人能指出我正确的方向吗?谢谢你

bash terminal diff cmp comm
1个回答
0
投票

如果“word”是 a 到 z 范围内的字母序列,则 grep

[a-z]+
可以进行单词拆分:

comm -23 \
  <(tr '[:upper:]' '[:lower:]' < text.txt | grep -Eo '[a-z]+' | sort -u) \
  <(sort -u dict.txt)
discreption
© www.soinside.com 2019 - 2024. All rights reserved.