john smith
john smith

Reputation: 152

Grep [[:punct:]] Doesn't Capture Punctuation

I am trying to test the [[:punct:]] character class. According to the grep manual it states that all these characters are considered punctuation:

'[:punct:]' Punctuation characters; in the ‘C’ locale and ASCII character encoding, this is

! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~."

So I tried with a comma:

$ cat testfile 
SANDWITCH
bread
103 mayo
,cant get this line to match with punct
$ grep [[punct:]] testfile 
$

Doesn't give any results. I was expecting the last line in the file to print.

Upvotes: 1

Views: 79

Answers (1)

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185560

You forgot a colon:

$ grep '[[:punct:]]' testfile 
#         ^

not

$ grep [[punct:]] testfile 

Upvotes: 2

Related Questions