help me

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help me
# 1  
Old 08-12-2011
help me

how can i search a pattern like atleast one alphabet and one digit and one special character in given file or string?
# 2  
Old 08-12-2011
There may be better ways in better shells, but you didn't say, so I'm assuming a rudimentary shell.

# Count kinds of chars by removing them with sed and measuring how many were removed.
STR2=`echo "$STR1" | sed 's/[a-zA-Z]//g'`
LEN2=`expr "${#STR1}" - "${#STR2}"`
echo "$LEN2 alphabetic chars"

STR3=`echo "$STR1" | sed 's/[0-9]//g'`
LEN3=`expr "${#STR1}" - "${#STR3}"`
echo "$LEN3 digits"

STR4=`echo "$STR1" | sed 's/[^a-zA-Z0-9 \t]//g'`
LEN4=`expr "${#STR1}" - "${#STR3}"`

echo "$LEN4 specials"

$ ./script
5 alphabetic chars
3 digits
3 specials

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question