If a have a variable with a first and last name.
and say the variable looks like this...
FIRST LAST
how could process the variable to look like
First .L
bash 3.2 (osx)
If a have a variable with a first and last name.
and say the variable looks like this...
FIRST LAST
how could process the variable to look like
First .L
bash 3.2 (osx)
try:
echo "$var"| awk '{$0=tolower($0); print toupper(substr($1,1,1)) substr($1,2) " ." toupper(substr($2,1,1))}' | read var
Bash version >= 4 supports case modification operations:
In lower versions you can use tr
instead. Here is an example:
NAME="FIRST LAST"
FRT="${NAME%% *}"
LST="${NAME##* }"
printf "%s%s .%s\n" "${FRT:0:1}" "$( echo ${FRT:1} | tr '[:upper:]' '[:lower:]' )" "${LST:0:1}"
echo $x | sed 's/\([^ ]* \)\(.\).*/\1.\2/'