【问题标题】:Bash - omit lines starting with a mis-spelled word (using hunspell)Bash - 省略以拼写错误的单词开头的行(使用 hunspell)
【发布时间】:2012-02-21 15:11:36
【问题描述】:

我有一个文件words.txt,其中每一行是一个单词,后跟一个TAB,后跟一个整数(表示单词的频率)。我想生成一个只包含单词拼写正确的行的新文件。

使用cat words.txt | hunspell -1 -G > ok_words.txt,我可以获得正确单词的列表,但我怎样才能包括每行的其余部分(即TAB 和数字)?

输入:

adwy  27
bird  10
cat   12
dog   42
erfgq 9
fish  2

期望的输出:

bird  10
cat   12
dog   42
fish  2

【问题讨论】:

    标签: bash command-line hunspell


    【解决方案1】:

    最简单的方法是使用join 命令:

    $ join words.txt ok_words.txt 
    bird 10
    cat 12
    dog 42
    fish 2
    

    或保留标签:

    $ join -t $'\t' words.txt ok_words.txt 
    bird    10
    cat 12
    dog 42
    fish    2
    

    【讨论】:

    • 在没有临时文件的单行中:join words.txt <(hunspell -1 -G < words.txt)
    • 这很好用,谢谢。 (我已将此与@l0b0 的建议结合起来以获取join -t $'\t' words.txt <(hunspell -1 -G < words.txt) > ok_words.txt
    猜你喜欢
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2010-10-16
    • 2018-11-25
    • 2020-10-26
    • 2011-01-01
    • 2021-12-18
    • 2015-05-06
    相关资源
    最近更新 更多