gpt4 book ai didi

shell - 在大文件中搜索单词而不打印整行

转载 作者:行者123 更新时间:2023-12-04 19:14:08 24 4
gpt4 key购买 nike

我有一个大的 xml 文件,它连接在一条长线上。在不一次将整个文件加载到内存中的情况下搜索单词的最佳方法是什么? grep 打印出整行,在我的例子中是整个 500MB 文件。

最终结果将是查看该单词及其周围的内容以了解其上下文。

最佳答案

例如,您想查看单词 three以及围绕它的另一个词:

$ echo "one two three four five four three two one" |egrep -o '\w+ three \w+'  
two three four
four three two

关于shell - 在大文件中搜索单词而不打印整行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44771054/

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