Help with grep / regular expression

Hi,

Input file:

-13-
-1er-
-1xyz1-
-1xz12-
-2ab1-
-2ab2--
-143-

Code:

grep '^[\-][0-9][a-z]*[0-9]\-' input.txt

Wrong output:

-13-
-1xyz1-
-2ab1-
-2ab2--

Expected output:

-1xyz1-
-2ab1-

This is what i am trying to do:
1)starts with - as first one
2) second character any number
3) third one any letter a to z
4) penultimate char - any number
5) last one is with -

Thanks in advance . :b:

Hi.

Your description could be considered slightly ambiguous, but:

$ egrep '^-[0-9][a-z]+[0-9]-$' file1
-1xyz1-
-2ab1-
1 Like

Hi Scottn,
just curious, is it not possible to do it with grep / awk ?

He is using grep, ie. egrep is like grep -E.

And the awk is the same:

$ awk '/^-[0-9][a-z]+[0-9]-$/' file1
-1xyz1-
-2ab1-