Home > OS >  Grep [[:punct:]] Doesn't Capture Punctuation
Grep [[:punct:]] Doesn't Capture Punctuation

Time:11-29

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.

CodePudding user response:

You forgot a colon:

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

not

$ grep [[punct:]] testfile 
  •  Tags:  
  • bash
  • Related