Quote:
Originally Posted by brgr88
Is there a way to print the member characters of the various POSIX character classes?
|
Perhaps I don't understand the nuances of the problem. Here's an approach which might be useful. I don't know enough bash to write a character string containing every character and have used this ...
Code:
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
... to represent such a string. See what can be done with it. This code ...
Code:
echo; echo "This is the character class [:digit:]"
printf "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
|sed 's/./&\n/g' \
|grep [[:digit:]] \
|paste -s -d"\0"
echo; echo "This is the character class [:upper:]"
printf "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
|sed 's/./&\n/g' \
|grep [[:upper:]] \
|paste -s -d"\0"
echo; echo "This is the character class [:lower:]"
printf "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
|sed 's/./&\n/g' \
|grep [[:lower:]] \
|paste -s -d"\0"
... produces this result ...
Code:
This is the character class [:digit:]
0123456789
This is the character class [:upper:]
ABCDEFGHIJKLMNOPQRSTUVWXYZ
This is the character class [:lower:]
abcdefghijklmnopqrstuvwxyz
These three similar code snippets may be combined ..
Code:
for j in digit upper lower
do
echo; echo "This is the character class [:$j:]"
printf "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" \
|sed 's/./&\n/g' \
|grep [[:$j:]] \
|paste -s -d"\0"
done
Daniel B. Martin