LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   A question need your kind help! (https://www.linuxquestions.org/questions/linux-newbie-8/a-question-need-your-kind-help-768856/)

jcky 11-13-2009 03:21 AM

A question need your kind help!
 
If you want to match only numbers, you might use:
[[:digit:]]

Could you please help me to give an example on how to use [[:digit:]]?

Thanks

Br.

centosboy 11-13-2009 03:37 AM

Quote:

Originally Posted by jcky (Post 3755260)
If you want to match only numbers, you might use:
[[:digit:]]

Could you please help me to give an example on how to use [[:digit:]]?

Thanks

Br.

Code:


cat count
test 1
test 5
test 9
test 13
test 17
test 21
test 25
test 29
test 33
test 37
test 41
test 45
test 49
test 53
test 57
test 61
test 65
test 69
test 73
test 77
test 81
test 85
test 89
test 93
test 97


then, remove digits (substitute with nothing)

Code:

cat count | sed 's/[[:digit:]]//g'
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test
test


pixellany 11-13-2009 05:39 AM

Quote:

Originally Posted by jcky (Post 3755260)
If you want to match only numbers, you might use:
[[:digit:]]

Could you please help me to give an example on how to use [[:digit:]]?

Thanks

Br.

Where did you find this?

This is what is generally called a "regular expression" (AKA regex)---which I think can be defined as a string of characters used to designate classes or types of data as opposed to specific data. Examples:

"." = any character
"*" = any number of the preceding regex
thus:
".*" = any number of characters

regexes are used in a wide variety of utilities--eg SED, AWK, GREP--and in programming languages such as PERL.

[ ] defines a "character class", and [:digit:] is a character type
[[:digit:][:blank:]] = a single number or a white space

Good tutorial here:
http://www.grymoire.com/Unix/


All times are GMT -5. The time now is 10:32 PM.