Home » Infrastructure » Unix » grep command
grep command [message #277282] Mon, 29 October 2007 06:59 Go to next message
gajini
Messages: 262
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: 3212
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: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
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: 262
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: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
See Thomas answer.

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


Current Time: Sat Nov 23 22:29:00 CST 2024