Redian新闻
>
向高人请教:怎么从大量的文件中grep
avatar
向高人请教:怎么从大量的文件中grep# Unix - 噫吁兮,危乎高哉
n*r
1
Hi,
Any one know how to use grep. I got the following error:
Arguments too long
I do some research on this issue. Some one said I can use xargs. The I try:
find . -type f |xargs grep "Run_Time" *
I get the error again.
各位高人可有什么建议?我知道文件的数目很大。不知谁有写过scripts.
或者用其他方法。比如怎么按文件生成的时间来查。先grep今天生成的文件,在grep昨
天生成的文件。
先谢了。
avatar
w*m
2
Here is my favorite grep command,
maybe you can modify it,
find .-name '*' -exec grep "Run_Time" {} \; -print
I think you can change -name to -type

【在 n**r 的大作中提到】
: Hi,
: Any one know how to use grep. I got the following error:
: Arguments too long
: I do some research on this issue. Some one said I can use xargs. The I try:
: find . -type f |xargs grep "Run_Time" *
: I get the error again.
: 各位高人可有什么建议?我知道文件的数目很大。不知谁有写过scripts.
: 或者用其他方法。比如怎么按文件生成的时间来查。先grep今天生成的文件,在grep昨
: 天生成的文件。
: 先谢了。

avatar
n*r
3
I try your suggestion, but I got the "Arguments too long" Error.
Thank you any way. This is a good idea.
avatar
j*y
4
"Arguments too long" Error means your file list is too big for find to
handle. Try to use perl, here's how:
perl -e 'opendir(DIR, "."); @all = grep //, readdir DIR; closedir
DIR; for (@all) { do something }'
avatar
r*z
5
你没用对xargs,建议看看它的man先
这个问题来自于你给shell的通配符*,是它被shell展开后过长造成的,
而xargs其实就是用来避免shell掺和

【在 n**r 的大作中提到】
: Hi,
: Any one know how to use grep. I got the following error:
: Arguments too long
: I do some research on this issue. Some one said I can use xargs. The I try:
: find . -type f |xargs grep "Run_Time" *
: I get the error again.
: 各位高人可有什么建议?我知道文件的数目很大。不知谁有写过scripts.
: 或者用其他方法。比如怎么按文件生成的时间来查。先grep今天生成的文件,在grep昨
: 天生成的文件。
: 先谢了。

avatar
v*r
6
楼上说的对,应把 ‘*' 从 grep 里去掉,不然即使不报 'argument too long'的错,
返回的结果都是 duplicate 的 (因为 grep 了两遍)

【在 r*****z 的大作中提到】
: 你没用对xargs,建议看看它的man先
: 这个问题来自于你给shell的通配符*,是它被shell展开后过长造成的,
: 而xargs其实就是用来避免shell掺和

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。