由买买提看人间百态

topics

全部话题 - 话题: grep
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
s******a
发帖数: 517
1
你的意思:grep abc inputfile |grep -v bcd
需要两次grep,我只想用一次,原因是我要找符合条件的下一行,比如inputfile如下
0 abcd
1 unmatch ha ha
2 abcxyz
3 match ha ha
我只想显示含ha的第3行。如果一个grep可以做到过滤出第2行的话,可以用以下命令:
grep unknown_pattern -A1 inputfile |grep ha
g*******0
发帖数: 127
2
来自主题: Linux版 - 问一个grep使用的问题
在本地目录下有一系列文件,文件名开头以"01 - F", "02 - F", "03 - F" ...为始,
文件名中间有空格。想找出那个以"01 - F"的文件,使用grep:
$grep -irl '^01s-sF'
则没有任何文件列出。
如果用:
$grep -irl '^01'
则有很多文件名中带01的文件名会列出来,包括那个"01 - F"的文件名。不知道为什么
'^'不工作。
使用 $grep -irl "^01" 是一样的。
使用 $grep -irl "^01 - F" 则还是没有任何文件列出。
使用pipeline也不行:$ ls -1 | grep -irl '^01' 效果是一样的。
这种情况下怎么解决啊?
i***r
发帖数: 1035
3
来自主题: Linux版 - grep 的很奇怪的现象
你是assume pipe左边先完成了再右边
实际不是这样的,grep也是一个进程,会被ps捕获
如果你不想显示 grep,需要
ps | grep abc | grep -v "grep"
A******a
发帖数: 61
4
【 以下文字转载自 Linux 讨论区 】
发信人: Ataraxia (静), 信区: Linux
标 题: how to use grep/sed to remove newlines?
发信站: BBS 未名空间站 (Sat Oct 18 10:48:52 2008)
i am trying grep some text from a file then return some words:
grep "^>start" textfile.txt
but it always returns results one each line:
A
B
C
I want to have it as: A B C ..., so I tried to use sed:
grep "^>start" textfile.txt | sed -e 's/\n//'
it doesn't work, anyone knows how to solve this?
Thanks.
w*s
发帖数: 7227
5
来自主题: Linux版 - grep cannot handle "" ?
i have a file like this,
123Name=456
123MyName=456
now want to grep and JUST get the 1st line,
tried
grep "Name" file
grep "\Name" file
grep "/Name" file
all come back with 2 lines,
any suggestions ? thanks !
A******a
发帖数: 61
6
【 以下文字转载自 Linux 讨论区 】
发信人: Ataraxia (静), 信区: Linux
标 题: how to sed from grep output in c shell?
发信站: BBS 未名空间站 (Fri Jan 25 11:45:51 2008)
by using
foreach i (*.txt)
grep -o 'Modules:[0-9]' $i
end
i got return like
Modules:2
Modules:1
Modules:10
Modules:0
Modules:7
...
I want to cut off "Modules:" and only keep the integer number, how should i
use sed based on this output?
grep ... | sed
or
sed ... $(grep...)
Thanks.
b***y
发帖数: 2799
7
☆─────────────────────────────────────☆
nkw (非死非活) 于 (Sat Jul 19 03:08:26 2008) 提到:
今天浪费很多时间在一个很简单的regex上,原来是grep没有\t (tab).有没有什么
option让这些程序使用一个统一的regex?对不常用的人要记住这些细微差别不容易。
还遇到一怪事,我的数据是三个字段以tab分割的结构,第三个日期字段很多为空字段。
xxxx{tab}yyyy{tab}12/31/2007
xxxx{tab}yyyy{tab}
xxxx{tab}yyyy{tab}11/30/2007
xxxx{tab}yyyy{tab}
当时我不知道grep的tab输入时不得不先用sed把\t换成|。
sed 's/\t/|/g' file|grep "[^|]*|[^|]*|.+" 得不到任何结果。
sed 's/\t/|/g' file|grep "[^|]*|[^|]*|[0-9]+" 就能有输出。
前一个有什么问题?
☆────────────────────────────────────
c**e
发帖数: 3760
8
来自主题: Unix版 - [转载] qestion about grep
【 以下文字转载自 Programming 讨论区 】
【 原文由 cure 所发表 】
grep 如果找不到匹配,就return 1 which is considered error.
我的tcsh script又希望能用-e option (一有错就exit),
但是就因为grep的缘故不能用,否则grep不到匹配就退出了。
有没有办法解决这个问题,比如执行grep之前ignore errors,
执行完了有改成有错就退出。
n**r
发帖数: 183
9
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昨
天生成的文件。
先谢了。
r**u
发帖数: 1567
10
来自主题: JobHunting版 - grep + perl regular expr (转载)
【 以下文字转载自 Linux 讨论区 】
发信人: raou (raou), 信区: Linux
标 题: grep + perl regular expr
发信站: BBS 未名空间站 (Thu Feb 25 16:08:55 2010, 美东)
想用grep+perl regular expression在文件里找一些东西,但是遇到这个问题。如何解
决?多谢
grep: Support for the -P option is not compiled into this --disable-perl-
regexp binary
h***r
发帖数: 726
11
来自主题: Linux版 - Grep 能作这个吗?
【 以下文字转载自 Unix 讨论区 】
发信人: haier (no nickname), 信区: Unix
标 题: Grep 能作这个吗?
发信站: BBS 未名空间站 (Thu May 14 17:28:28 2009), 转信
我有文本文件如下
1 200
2 199
4 198
13 190
2 180
...
可以看出已经按照第二个字段排序了。
现在我想找出 top 100 (针对第二个字段而言)
但是第一个字段的值必须大于5
我知道如果想找等于5,用grep
cat a | grep "^5\t" |head
但是对于大于5就傻眼了。
用sed行吗?怎么写script?
编一个解决不是solution, 肯定有linux/unix command吧?
thanks!
f********o
发帖数: 1163
12
来自主题: Linux版 - grep 的很奇怪的现象
想用
ps | grep "abc"
判断abc是否在运行
结果每次都会有一个进程,就是grep本身产生的: grep abc
为啥啊?难道pipe的时候不是先运行pipe左边,再把结果输到右边么?
d****e
发帖数: 499
13
来自主题: Linux版 - enhanced grep
多谢, 一个在多个服务器grep的问题,以前只有两个服务器,一个一个去grep问题不
大,现在一下子增加到20(server-001到server020)个,一个一个查找很花时间,检查
每个服务器的步骤是这样的:
1. login the account:
ssh haadm@server-001
2. 切换到log 目录,这个目录可能有上百个log4j生成的文件
cd /root/var/log/huge-app
3. 查找指定的字符串在哪个文件
grep -n 'mystringTobeSearched' *.*
每个服务器的login帐号密码已及log的目录结构都是一样(/root/var/log/huge-app),
有啥办法可以一下查找指定的字符串在那个服务器的哪个文件?
b*s
发帖数: 82482
14
来自主题: Linux版 - enhanced grep
写一个bash script不就行了么?

多谢, 一个在多个服务器grep的问题,以前只有两个服务器,一个一个去grep问题不
大,现在一下子增加到20(server-001到server020)个,一个一个查找很花时间,检查
每个服务器的步骤是这样的:
1. login the account:
ssh haadm@server-001
2. 切换到log 目录,这个目录可能有上百个log4j生成的文件
cd /root/var/log/huge-app
3. 查找指定的字符串在哪个文件
grep -n 'mystringTobeSearched' *.*
每个服务器的login帐号密码已及log的目录结构都是一样(/root/var/log/huge-app),
有啥办法可以一下查找指定的字符串在那个服务器的哪个文件?
j**********p
发帖数: 22
15
grep -o 'Modules:[0-9]' $i | sed 's/Modules://g'
or
grep -o 'Modules:[0-9]' $i | awk -F ":" '{print $2}'
or
grep -o 'Modules:[0-9]' $i |sed 's/^.*://g'
h**o
发帖数: 548
16
来自主题: Programming版 - how to grep one of the strings?
I can now use
grep '^ *icap_enable *off' my_file
to grep "icap_enable off".
Then how to grep "icap_enable on" or "icap_enable off"?
Thanks
T********r
发帖数: 6210
17
来自主题: Unix版 - grep usage
sorry the previous solution is wrong. it just proves one thing:
for every complex problem there is a solution that is simple,
neat and wrong. ;-)
here's the correct one, hopefully
grep -l aaa `grep -l bbb files-to-grep`
k*****h
发帖数: 33
18
grep -E ‘foo[^foo]+$’ filename

【 以下文字转载自 JobHunting 讨论区 】
发信人: mitliqiang (li qiang), 信区: JobHunting
标 题: An interview question for grep in linux
发信站: BBS 未名空间站 (Mon Jan 26 13:48:58 2009)
Using grep, identify the regular expression in a given string such that the
pattern does not repeat. For example, to identify the pattern 'foo' only
once in an input.
'jhkhfoojkkj' should be identified right
'kjhfooaaaaafoo' should not.
How to do that? I tested some, but can not succeed.
Thanks...
p*****s
发帖数: 344
19
grep -A1 -e "abc[^d]" | grep ha
s*****k
发帖数: 604
20
来自主题: Linux版 - grep 的问题
多谢,在cygwin 的可以用,看了一下帮助还可用 grep -A1
但是在solaris里不能用啊,那里面的grep的options 好像很少。
r**u
发帖数: 1567
21
来自主题: Linux版 - grep + perl regular expr
想用grep+perl regular expression在文件里找一些东西,但是遇到这个问题。如何解
决?多谢
grep: Support for the -P option is not compiled into this --disable-perl-
regexp binary
S*******h
发帖数: 7021
22
来自主题: Linux版 - grep 的很奇怪的现象
In my understanding, Ps is used to provide about currently running processes
, including their PIDs. With pipes, the standard output of ps command is fed
into the standard input of grep. If the grep result shows abc, it means
the abc process is running.
s*******f
发帖数: 757
23
来自主题: Programming版 - Usage of Grep???help!!!
I have data files with format like this:
year,mon,day,data.....
All are numbers and are seperated by coma. Can someone give me some suggestion
how I can use grep to extract the data at certain month, say, March-May.
I tried :
grep "^[[:digit:]\{\4\}[, ][3-5]]" inputfile >outputfile
It doesn't work.
Thanks!!!
s*****c
发帖数: 753
24
My data look like this
opt.test.xxx.data=some data
opt.test.xxx.dim.x=some data
opt.test.xxx.dim.y=some data
opt.test.xxx.dim.z=some data
opt.test.xxx.length=some data
opt.test.xxx.tree=some data
I already use grep to extract those lines from a file to a new file using
grep '\.roi\.' file1 > file2
I suppose I will use s/(? something like [data|dim\.x|...] to look ahead?
d******i
发帖数: 7160
25
比如某行有两个不相邻的字符串
XXX "str1" XXX "str2" XXX
都被""包裹着。
目前我知道grep命令
grep -o "\"\w*\".*\"\w*\"" file.txt
能找到这些行并输出 "str1" XXX "str2" 的部分:
"str1" XXX "str2"
却没办法滤掉XXX只输出那两个些被匹配到的串:
"str1" "str2"
请指教。
e*******o
发帖数: 4654
h****t
发帖数: 93
27
hehe.:) a silly one. :) grep whatever */* and then grep whatever */*/* ...
c*****t
发帖数: 1879
28
so many awk fans. Sigh, I don't know awk, but other common commands
work well too.
echo `grep xxx | cut -d: -f2`
Of course, it runs two instead of one, but I would assume that the
bottleneck was the grep part...
w*******o
发帖数: 32
29

grep ULL your_input | grep -v NULL
t**c
发帖数: 97
30
来自主题: Unix版 - grep 在solaris下搞不定
if you've gnu grep installed on solaris, just use ggrep instead of grep.
T********r
发帖数: 6210
31
来自主题: Unix版 - grep usage
a silly way: grep aaa file | grep bbb
a*****j
发帖数: 13
32
来自主题: Unix版 - [转载] grep question
【 以下文字转载自 Linux 讨论区 】
【 原文由 AgehaDJ 所发表 】
for example,
if you want to find files that contain both "linux" and "unix",
so we should do it in shell
foreach(`grep -l "linux" *.*`)
grep "unix";
is it correct? or not?
or how should I do it?
u****s
发帖数: 2186
33
来自主题: Unix版 - [转载] grep question
grep linux *.* |grep unix
w*m
发帖数: 1806
34
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
v*****r
发帖数: 1119
35
楼上说的对,应把 ‘*' 从 grep 里去掉,不然即使不报 'argument too long'的错,
返回的结果都是 duplicate 的 (因为 grep 了两遍)
m********g
发帖数: 9
36
【 以下文字转载自 JobHunting 讨论区 】
发信人: mitliqiang (li qiang), 信区: JobHunting
标 题: An interview question for grep in linux
发信站: BBS 未名空间站 (Mon Jan 26 13:48:58 2009)
Using grep, identify the regular expression in a given string such that the
pattern does not repeat. For example, to identify the pattern 'foo' only
once in an input.
'jhkhfoojkkj' should be identified right
'kjhfooaaaaafoo' should not.
How to do that? I tested some, but can not succeed.
Thanks...
r***n
发帖数: 553
37
当时用的是linux 或者其它 类-unix 操作系统
看这照片就知道了
所谓“编一个程序过滤Thallium”,其实很简单
就是 cat all emails| grep Thallium|wc
一句就搞定了
(最多搞个循环,把所有的信遍历一遍,实在是菜鸟啊!)
l*********8
发帖数: 4642
38
一句script:
grep -i -l thallium *.txt | wc -l
假设每封邮件存放在一个txt文件里, 上面一句能得出有多少封邮件提到了铊。

题?
s****n
发帖数: 700
39
来自主题: JobHunting版 - grep + perl regular expr (转载)
use pipe (|)
grep "expr_grep_format" | perl -nle "expr_perl_format"
K******g
发帖数: 1870
40
我见到好多面试题目就是要用grep
那些option和regex语法好难记啊。
不知道大家是怎么做的?
a********n
发帖数: 369
41
来自主题: JobHunting版 - 一个grep(?)问题的求助
怎样找出文件中所有 出现次数小于某数值 的所有字符?用grep能实现吗?不太懂
linux……谢谢呀!
c*****t
发帖数: 1879
42
echo `grep ">start" textfile.txt`
s******a
发帖数: 517
43
1.使用一次grep如何显示包含字串abc而不包含字串cde的行?
2.ls可以彩色显示,more可以黑白分屏显示。怎样才能彩色分屏显示文件及目录?
谢谢
u*********r
发帖数: 2735
44
man grep, hint -v
most
s*****k
发帖数: 604
45
来自主题: Linux版 - grep 的问题
比如说我有个文件 a.txt
里面是这样的。
aaaa
1 2 3 4
bbbb
2 3 2 1
cccc
5 6 7 8
.
.
.
abcd
9 8 7 1
.
.
.
EOF
我想用grep 找到 abcd 那一行,然后显示 abcd 那一行和它的下一行,像这样
abcd
9 8 7 1
该如何做?
r******h
发帖数: 656
46
来自主题: Linux版 - grep 的问题
grep -n1
C********s
发帖数: 120
47
来自主题: Linux版 - grep + perl regular expr
download src and compile a grep yourself
b*******f
发帖数: 428
48
一个文件,里面有
...
INFO [#10001] : XXXXXXXXXXXXXX
: Y1Y1Y1Y1Y1Y1Y1
INFO [#10001] : XXXXXXXXXXXXXX
: Y2Y2Y2Y2Y2Y2Y2
WARN [#30001] : XXXXXXXXXXXXXXXXXX
: Y3Y3Y3Y3Y3Y3Y3
(Y1Y1Y1Y1Y1Y1Y1和Y3Y3Y3Y3Y3Y3Y3是信息第一次出现的第二行,用grep "[#10001]" -
m 1 -A 1 可以抓到)
想用一行command,pipeline提取出结果,最后是这样的:(第一列是统计数量)
2 [#10001] INFO : Y1Y1Y1Y1Y1Y1
1 [#30001] WARN: Y3Y3Y3Y3Y3Y3
请问如何做到?用perl也行
鼓弄了半天,现在只能做到
2 [#10001] INFO :
1 [#30001] WARN:
多谢!
m**k
发帖数: 290
49
来自主题: Linux版 - grep 的很奇怪的现象
ps | grep "[a]bc"
u*********r
发帖数: 2735
50
来自主题: Linux版 - grep 的很奇怪的现象
abc is the arguments of process grep

processes
fed
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)