Operating System - HP-UX
1819681 Members
3639 Online
109605 Solutions
New Discussion юеВ

Using regular expr. in a grep command

 
Ronald Cogen
Frequent Advisor

Using regular expr. in a grep command

Hi out there,

I want to grep files with a certain prefix and with any combination and digits of numbers.

# grep -L LTA'[0-9]' *

will return only on number. But what if I want to represent any number of numbers? My fantasy dosen't help either.

Ron
I've been down so long it looks like up to me
5 REPLIES 5
Jeff Schussele
Honored Contributor

Re: Using regular expr. in a grep command

Hi Ron,

I don't think "L" is a valid grep parm.
And the "l" will only return filenames with that pattern within the file itself. If you want to find filenames then I'd use find & pipe it to grep

find . -name -exec grep 'LTA[0-9]'

for all numbers. And use this format for whatever numbers you wish

find . -name -exec grep 'LTA[24680]'

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Paula J Frazer-Campbell
Honored Contributor

Re: Using regular expr. in a grep command

Hi

Have you tried a grep/egrep on a grep


ls -l | grep LTA | egrep " [1-9]"


Paula
If you can spell SysAdmin then you is one - anon
Rodney Hills
Honored Contributor

Re: Using regular expr. in a grep command

If I read your question right, you want to find LTA followed by any number of digits.

A typical regexp for grep would be
grep -L LTA'[0-9][0-9]*' *

This would look for LTA followed by a digit, followed by zero or more additional digits.

HTH

-- Rod Hills
There be dragons...
Robin Wakefield
Honored Contributor

Re: Using regular expr. in a grep command

Hi Ron,

Not sure I understand the question:

grep -lE LTA[0-9]+ *

will list all files containing LTA plus at least one number.

Rgds, Robin
Larry Reinhart
Advisor

Re: Using regular expr. in a grep command

Hi Ron,

If you are searching for that pattern within a file you could also use a character class expression:

grep -l LTA"[[:digit:]]" *

This would find the LTA followed by any number of digits.

See man 5 regexp for more on character classes.

Have fun! :-)
Larry