Reputation: 26958
In file named appleFile:
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###
Upvotes: 1
Views: 543
Reputation: 14137
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
.
Upvotes: 2
Reputation: 8295
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"
Upvotes: 2