gpt4 book ai didi

查找二元组的 Shell 脚本

转载 作者:行者123 更新时间:2023-12-04 03:21:16 27 4
gpt4 key购买 nike

我正在制作一个 shell 脚本来查找双字母组,这在某种程度上是可行的。

#tokenise words
tr -sc 'a-zA-z0-9.' '\012' < $1 > out1
#create 2nd list offset by 1 word
tail -n+2 out1 > out2
#paste list together
paste out1 out2
#clean up
rm out1 out2

唯一的问题是它将前一个句子的结尾和开头的单词配对。

例如“hello world”这两个句子。和'foo bar'。我会和'世界'取得联系。咕'。是否可以使用 grep 或其他方式过滤掉这些内容?

我知道我可以使用 grep [.] 找到所有包含句号的双字母组,但也可以找到合法的双字母组。

最佳答案

只需将粘贴行替换为:

paste out1 out2 | grep -v '\..'

这将过滤掉所有包含句点但不是行的最后一个字符的行。

关于查找二元组的 Shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/245082/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com