我想search包含“已上传”但不包含“09”
有没有办法做到这一点与grep?
(如果有关系的话,CentOS 5.6)。
我通常链接greps来做到这一点。
grep uploaded $file | grep -v 09
您可以使用-v选项来grep来反转匹配
grep uploaded file | grep -v 09
会做你想要的。 这发现包含上传的行被传递到一个grep命令忽略其中的09行的行。
这不是使用grep
– 但任何时候我有一个需要比一个基本的grep
,我转向我最喜欢的, sed
。 当然,我必须把grep
命令链接在一起。
使用这个命令来做到这一点:
sed -n '/09/d; /uploaded/p' file
只有一个命令(不是两个)。
试试简单:
( grep -v 09 | grep uploaded ) < file
例:
$ cat file 1 uploaded 09 2 09 3 uploaded 4 text $ ( grep -v 09 | grep uploaded ) < file 3 uploaded