risby
Programmer
- Feb 27, 2002
- 84
I have some email addresses and I want to strip out the name. They are all similar format: forename dot surname at domain, and they are usually all lower case. I know it's very old fogeyish of me but I thought it would be better to have the first letter of the extracted names in uppercase. Below is what I tried (apart from the awk it's Korn shell syntax, ascii char set, ADM holds email address and NME should end up with the name component)
but I get a zero instead of the uppercase initial I want, i.e. I get 0red 0loggs instead of Fred Bloggs.
It's some difference between awk and c handling of datatypes I guess but I can't see what the problem is.
==========================================
Some cause happiness wherever they go; others whenever they go.
Code:
NME=$( echo ${ADM} | cut -d'@' -f1 | tr '.' ' ' |
awk '
{
for (i=1; i<=NF; i++) {
initial=substr($i, 1, 1)
if (initial > "Z") {
initial += "a" - "A"
$i=initial substr($i, 2)
}
}
print $0
}
'
)
It's some difference between awk and c handling of datatypes I guess but I can't see what the problem is.
==========================================