Operating System - Linux
1753914 Members
8911 Online
108810 Solutions
New Discussion юеВ

Re: How to grep using "*"

 
SOLVED
Go to solution

How to grep using "*"

I have a file called filelist with following lines in them:

/cdrom
/usr/local/bin
/oracle/ABC/sapdata
/oracle/DEF/sapdata
/oracle/ABC/archlog

I want to grep out /oracle/*/sapdata and am using the following command which is not working:

# grep -v /oracle/*/sapdata filelist

I get the following output:
/cdrom
/usr/local/bin
/oracle/ABC/sapdata
/oracle/DEF/sapdata
/oracle/ABC/archlog

I am expecting /oracle/ABC/sapdata and /oracle/DEF/sapdata to be excluded.

Please help, thanks.
10 REPLIES 10
Patrick Wallek
Honored Contributor

Re: How to grep using "*"

Do you have other lines with 'sapdata' in them?

Could you do:

grep -v sapdata filelist
Marvin Strong
Honored Contributor
Solution

Re: How to grep using "*"


grep -v "/oracle/.*/sapdata" filelist

I think that will exclude anything that starts with oracle and ends with sapdata.

* in regex means match 0 or more of the preceding character.
Alan Meyer_4
Respected Contributor

Re: How to grep using "*"

try this

grep '^/oracle/' filelist |grep '/sapdata$'
" I may not be certified, but I am certifiable... "
Torsten.
Acclaimed Contributor

Re: How to grep using "*"

Hi,

have a look at this page, it gives a good idea how to use wildcard with grep.
(You'll have more fun than reading a man page)
Many examples for beginners!

http://pegasus.rutgers.edu/~elflord/unix/grep.html#wildcards

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Alan Meyer_4
Respected Contributor

Re: How to grep using "*"

oops, sorry I miss read your request... never mind
" I may not be certified, but I am certifiable... "
Alan Meyer_4
Respected Contributor

Re: How to grep using "*"

revised...

grep -v '^/oracle/' test.dat |grep -v '/sapdata$'
" I may not be certified, but I am certifiable... "
Rodney Hills
Honored Contributor

Re: How to grep using "*"

I think you only need to put quotes around your search text.

# grep -v "/oracle/*/sapdata" filelist

Otherwise the shell will try to expand the file paths.

HTH

-- Rod Hills
There be dragons...
Sandman!
Honored Contributor

Re: How to grep using "*"

I agree with Marvin and Rodney's solution i.e.

# grep -v '/oracle/.*/sapdata'

should do the trick...regards!
John E.Ophious
Regular Advisor

Re: How to grep using "*"

Pactiv Development,

grep with a combination of -v and some quotations around your search string just might do the trick.

Peace and Chicken Grease,

John E. Ophious