开发者

How to grep this kind of pattern out using this "grep" command?

In file named appleF开发者_运维知识库ile:

1.apple_with_seeds###
2.apple_with_seeds###
3.apple_with_seeds_and_skins###
4.apple_with_seeds_and_skins###
5.apple_with_seeds_and_skins###
.....
.....
.....

How can i use the grep command to grep the pattern only with "apple_with_seeds"??? It is supposed that there is random characters after seeds and skins.

Result:
1.apple_with_seeds###
2.apple_with_seeds###


Maybe something like this will work for you:

grep 'apple_with_seeds[^_]' appleFile

That will print all lines having no _ character after seeds. You can add other characters to exclude to between the brackets (but after the ^), e.g. [^_a-z] will additionally exclude all lower case letters.

Or you could explicitly include some characters (like #):

grep 'apple_with_seeds[#]*$' appleFile

And again you can add arbitrary characters between the brackets, e.g. [#A-Z] would match any of the characters # or A-Z.


cat appleFile | grep "apple_with_seeds$"

UPDATE: if you want to exclude something, try -v option:

 cat appleFile | grep "apple_with_seeds$" | grep -v "exclude_pattern"


Try this

cat appleFile|grep -i seeds$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜