Operating System - HP-UX
1833758 Members
2935 Online
110063 Solutions
New Discussion

Adding spaces among two or more variables ....

 
SOLVED
Go to solution
Manuales
Super Advisor

Adding spaces among two or more variables ....

hi ..

this is the code in question:
a=`perl -MPOSIX -le 'print strftime "%b %d",localtime(time-86400)'`
echo valor de a $a
case `echo $a | cut -d" " -f2 | cut -c1 | sed 's/ //g'` in
"0" ) echo estoy adentro del case; mm=`echo $a | cut -d" " -f1`
dd=`echo $a | cut -d" " -f2 | cut -c2`; esp=" " ; b="$mm$esp$dd" ;;
esac


$ ./printers_in_use.sh
value of a: May 01
estoy adentro del case
esto vale ahora b: May 1

how can i do?
i need b appears as follows: May 1 (with two spaces between May and 1)

please let me kow.
thanks.
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Adding spaces among two or more variables ....

Hi Manuales:

> need b appears as follows: May 1 (with two spaces between May and 1)

You use this:

# perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'

That is, change the "%d" to a "%e" just as the manpages for 'date' would show you.

Regards!

...JRF...
Manuales
Super Advisor

Re: Adding spaces among two or more variables ....

I did that
but i need "two spaces" not one ...
$ a=`perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'`
$ echo $a
May 1
$

how can i do it?
Manuales
Super Advisor

Re: Adding spaces among two or more variables ....

Im sorry
this is the correct script:

a=`perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'`
echo valor de a $a
case `echo $a | cut -d" " -f2 | cut -c1 | sed 's/ //g'` in
"0" ) echo estoy adentro del case; mm=`echo $a | cut -d" " -f1`
dd=`echo $a | cut -d" " -f2 | cut -c2`; esp=" " ; b="$mm$esp$dd" ;;
esac

$ a=`perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'`
$ echo $a
May 1

i need two spaces instead of one in "May 1"
James R. Ferguson
Acclaimed Contributor

Re: Adding spaces among two or more variables ....

Hi (again) Manuales:

> $ a=`perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'`
> $ echo $a

The Perl is now correct, but your 'echo' is NOT. You need to double quote the variable you echo to preserve multiple spaces:

# echo "$a"

Regards!

...JRF...
Manuales
Super Advisor

Re: Adding spaces among two or more variables ....

$ a=`perl -MPOSIX -le 'print strftime "%b %e",localtime(time-86400)'`
$
$ echo "$a"
May 1


YOU ARE CORRECT !!!!!!!!!!!!
THANKS A LOT !!!!!
YOU ARE AMAZING !!!!!!!!!!