Home » Infrastructure » Unix » grep command
grep command [message #277282] Mon, 29 October 2007 06:59 Go to next message
gajini
Messages: 259
Registered: January 2006
Senior Member
Hi,

Please find the output of ls command,

$ls
1.txt
ex.awk
ex1.awk
ex123
num.sh
text.txt

To find the file names that is containing number in it,I used the following command,

$ ls | grep [^0-9]
1.txt
ex.awk
ex1.awk
ex123
num.sh
text.txt

but it's not giving the desired output Why it's so? Please correct if there is any mistake in the grep command to get the desired output...

Thanks..
Re: grep command [message #277284 is a reply to message #277282] Mon, 29 October 2007 07:17 Go to previous messageGo to next message
ThomasG
Messages: 3189
Registered: April 2005
Location: Heilbronn, Germany
Senior Member
The brackets are a little wrong.

Try

ls |grep ^[0-9]


Which means StartsWith[0-9]

[^0-9] evaluates to "contains something else than numbers", I think.

Re: grep command [message #277292 is a reply to message #277282] Mon, 29 October 2007 07:42 Go to previous messageGo to next message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:

To find the file names that is containing number in it

ls |grep [0-9]


Regards
Michel
Re: grep command [message #277402 is a reply to message #277292] Mon, 29 October 2007 23:37 Go to previous messageGo to next message
gajini
Messages: 259
Registered: January 2006
Senior Member
Sorry I made a typing mistake, I wants to find the filenames thats not containing number in it.

Thanks...
Re: grep command [message #277407 is a reply to message #277402] Mon, 29 October 2007 23:57 Go to previous message
Michel Cadot
Messages: 64139
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
See Thomas answer.

Regards
Michel
Previous Topic: installation problem
Next Topic: shmmax - memory chunks
Goto Forum:
  


Current Time: Fri Dec 09 02:22:54 CST 2016

Total time taken to generate the page: 0.20054 seconds