Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$ 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.

>Solution :

You forgot a colon:

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

not

$ grep [[punct:]] testfile 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading