Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Character Class ?

Status
Not open for further replies.

polar1

MIS
May 14, 2001
31
0
0
US
I am having a problem understanding how the character classes work using Posix. I am trying to extract a single digit from a string as follows:
rowa='1 2 3 4 5'
rowb=`echo $rowa |awk '{print $1,$2,$3,$4}'
for i in "$rowb
do
if [ "${i+[3[:digit:]}" = "3" ] # <- This returns1! Syntax problem!
then
echo "$i"
fi
done
 
polar1 -
I'm not clear exactly on what you're goal is, could you be more specific?

Anyway, for starters ...
1.) your rowa & rowb variables are identical
2.) you're missing a [ and a backtic `

Also, try this:
for i in $rowb
do
if [`echo $i | /usr/xpg4/bin/egrep [[:digit:]]` = 3 ]
then
echo $i
done


 
Thanks CPTK for your help. Sorry for the typo's.
My thoughts were to extract a single digit from rowa to test its value, (1|2|3|4|5)
The character class was confusing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top