相关疑难解决方法(0)

如何使用 -EXEC 对 FIND 的结果进行 grep 并仍输出到文件?

最好用例子来解释。

我可以:

find . -name "*.py" -type f > output.txt
Run Code Online (Sandbox Code Playgroud)

但是如何将输出存储到同一个文件中:

find . -name "*.py" -type f -exec grep "something" {} \
Run Code Online (Sandbox Code Playgroud)

我不能只是做

find . -name "*.py" -type f -exec grep "something" {} \ > output.txt
Run Code Online (Sandbox Code Playgroud)

find

90
推荐指数
3
解决办法
26万
查看次数

如何在终端中启动多线程grep?

我有一个文件夹,其中包含 250 多个文件,每个文件大小为 2 GB。我需要在这些文件中搜索字符串/模式并将结果输出到output文件中。我知道我可以运行以下命令,但是太慢了!!

grep mypattern * > output
Run Code Online (Sandbox Code Playgroud)

我想加快速度。作为一名 Java 程序员,我知道多线程可用于加快进程。我被困在如何以grep“多线程模式”启动并将输出写入单个output文件。

grep parallelism

46
推荐指数
2
解决办法
4万
查看次数

哪个是更好的搜索方式 - 使用正则表达式查找或使用 grep 查找?

这两种在所有子目录中递归搜索文件的方法中,哪个更快/更好?

find . -regex ".*/.*abc.*"
Run Code Online (Sandbox Code Playgroud)

或者

find . | grep ".*abc.*"
Run Code Online (Sandbox Code Playgroud)

grep find

4
推荐指数
2
解决办法
5801
查看次数

递归目录中的快速字符串替换

如何使用带有空格单引号的递归目录和文件名进行快速文本替换?最好使用标准的 UNIX 工具,或者一个众所周知的包。

find对于许多文件,使用速度非常慢,因为它为每个文件生成一个新进程,因此我正在寻找一种将目录遍历和字符串替换集成为一个操作的方法。

慢搜索:

find . -name '*.txt'  -exec grep foo {} \;
Run Code Online (Sandbox Code Playgroud)

快速搜索:

grep -lr --include=*.txt foo
Run Code Online (Sandbox Code Playgroud)

缓慢替换:

find . -name '*.txt' -exec perl -i -pe 's/foo/bar/' {} \;
Run Code Online (Sandbox Code Playgroud)

快速更换:

# Your suggestion here
Run Code Online (Sandbox Code Playgroud)

(这个速度相当快,但是是两次传递并且不处理空格。)

perl -p -i -e 's/foo/bar/g' `grep -lr --include=*.txt foo`
Run Code Online (Sandbox Code Playgroud)

recursive replace

0
推荐指数
1
解决办法
1213
查看次数

标签 统计

find ×2

grep ×2

parallelism ×1

recursive ×1

replace ×1