sed question

Hi, :slight_smile:
can any body explain the following statement
sed 's/[^[:digit:]\(\)- ]//g'

cheers
RRK

Removes characters other than digit , ( , ) , - and space in the input

hi,
what is the purpose of //g in the above statement.
any help ?

cheers
RRK

Sed's replacement mechanism works as follows:

's/regular expression/replacement/flags'

In your case, 's/[^[:digit:]\(\)- ]//g' here [^[:digit:]\(\)- ] is a regular expression and // is replacement and g is global flag. Above regular expression tells sed to match characters which are not digits, (, ), -, space and replace them with null string globally. So this sed statement will match all characters which are not digit, (, ), -, space and remove them.

Regards,
Tayyab