- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- bust up a variable
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 05:55 AM
03-16-2003 05:55 AM
I have a variable that contains all-capps of a persons last name.
1. how do i break up the variable into variables that only contain the characters?
2. how do I change from caps to lowercase?
3. how do i capitalize the 1st character?
4. also need to comply to creating userid's from these names, where the uid must be the first 7 characters of the last name and the 1st let of the first name.
5. also some last names are less than 7 characters, in that case more charaters must be used from the first name to make up 8 characters.
in ksh please.
I have 300 user accounts to create and they provided me with lastnames in caps in first names in lowercase.
Donny
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 06:28 AM
03-16-2003 06:28 AM
Re: bust up a variable
typeset -u VAR=abc
echo $VAR
ABC
typeset -l VAR=ABC
echo $VAR
abc
For putlling char's out of a string:
FOURTH=$(echo $VAR | cut -c 4)
TWO=$(echo $VAR | cut -c 2)
etc.
For question #5, about 7 or 8 chars.
Build your EIGHT VAR's and manipulate them anyway you want.
ONE
TWO
...
SEVEN = NULL?
EIGHT = NULL?
etc.
Get a copy of "The New Kornshell Command Reference " by Bolsky and Korn.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 07:29 AM
03-16-2003 07:29 AM
Re: bust up a variable
LASTNAME=ANDERSON
typeset -l $LASTNAME
echo $LASTNAME
anderson
or did I loose it all together.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:02 AM
03-16-2003 08:02 AM
Solution> LASTNAME=DONOVAN
> echo $LASTNAME| tr "[:upper:]" "[:lower:]"
> donovan
and if your new user's names are ina single file then you can use tr as follows:
> cat filename|tr "[:upper:]" "[:lower:]" >lowercase
and all uppercase in "filename" will be translated to lowercase in "lowercase"
...it would be
typset -l LASTNAME=ANDERSON
echo $LASTNAME
anderson
Rule #5 seems contrived to me. What happens when you eventually have a user whose first and last names combined do not total 8 characters?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:23 AM
03-16-2003 08:23 AM
Re: bust up a variable
#!/usr/bin/ksh
fname=
lname=
print "$fname $lname" | awk '
function modname(string) {
len=length(string);
if (len>7) len=6;
fchar=toupper(substr(string,1,1));
rest=tolower(substr(string,2,len));
return fchar rest
}
{
name=modname($1) modname($2);
len=length(name);
if (len>7) name=substr(name,1,8);
print name;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 08:56 AM
03-16-2003 08:56 AM
Re: bust up a variable
thanx for your tutorial
as for #5,
I think, one would want to use all the users last name, and oh, now I remember.
you start using charaters in the users first name.
and I guess, if the users last and first name combined is less than 8, they want it to be populated with something unique
interresting ....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:02 AM
03-16-2003 09:02 AM
Re: bust up a variable
#!/usr/bin/ksh
fname=
lname=
function modname {
typeset -u fchar
typeset -l rest
fchar=$(print $1 | cut -c 1)
rest=$(print $1 | cut -c 2-)
print "${fchar}$rest"
return
}
fname=$(modname $fname)
len=${#fname}
if [ $len > 7 ] ;then
fname=$(print $fname | cut -c 1-7)
fi
lname=$(modname $lname)
name="${fname}$lname"
len=${#name}
if [ $len > 8 ] ;then
name=$(print $name | cut -c 1-8)
print $name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:13 AM
03-16-2003 09:13 AM
Re: bust up a variable
thanx, a million. I am ok from here on. will send you the final script for critique
10 point for both.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:26 AM
03-16-2003 09:26 AM
Re: bust up a variable
elif [ $len < 8 ] ;then
set -A Chars a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 . /
while [ $len < 8 ]
do
num=$(($RANDOM / 512 ))
char=${Chars[$num]}
name="${name}$char"
len=${#name}
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2003 09:34 AM
03-16-2003 09:34 AM