0

grep how can I find all the user logins that end with 88 and 89 ? I can get logins ending with a number if I do grep "[0-9]" filename

2 Answers 2

1

If you only want to show those ending in 88 and 89, you can use grep -e "88$" -e "89$"

The '$' notates the end of the line.

1

You already know how to use character classes: [0-9] is a character class that means "all the digits from 0 until 9". You can use more specific sets as well. For instance, [89] means "either 8 or 9". Finally, in regular expressions, $ means "the end of the line". So, putting all this together, you can do:

grep '8[89]$' file

That will print any lines in the file file that end with an 8 followed by either another 8 or a 9, in other words, lines ending with 88 or 89.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .