3

I am using the below command in solaris

ls -l | grep '*PROC*'

But it is not working. I have many files that contain "PROC" in their name like "XREF_PROC.complete" but when I use the above command its not showing any output. When I use ls *PROC* its working but not working with grep.

Thanks

1 Answers1

10

tl;dr

You don't need a quantifier, just grep for PROC:

ls | grep PROC

long version

The asterisk in your ls line, is not the same as the one in your grep line.

When you have an unescaped asterisk on the command line, the shell will expand it before ls sees it, this is called globbing. An asterisk alone expands to all files in the current directory, try for example echo * . The *PROC* glob will expand to all files containing PROC.

The asterisk you are using with grep is escaped with single-quotes, and thus will be interpreted by grep. However, grep uses BREs by default (Basic Regular Expressions), where the asterisk works as a quantifier, and so requires some character or character class to quantify, e.g. '.*'.

barlop
  • 25,198
Thor
  • 6,763
  • 1
  • 40
  • 44