1827293 Members
2449 Online
109717 Solutions
New Discussion

Re: build a string

 
SOLVED
Go to solution
Claudio_17
Frequent Advisor

build a string

Hi,

how can build a string like this :

ENDED: Sat Apr 12


16 REPLIES 16
Pete Randall
Outstanding Contributor

Re: build a string

echo "ENDED: " `date`



Pete

Pete
Tom Geudens
Honored Contributor

Re: build a string

Hi,
echo "ENDED: $(date +'%a %b %d')"
Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
Bill McNAMARA_1
Honored Contributor

Re: build a string

echo "ENDED: Sat Apr 12"
works too!
It works for me (tm)
Chris Vail
Honored Contributor

Re: build a string

STRING="ENDED: Sat Apr 12"

Perhaps your question is badly worded, though: this is too easy. Here's another:

DATE="Sat Apr 12"
STATUS="ENDED:"
STRING="$STATUS $DATE"


Chris
Claudio_17
Frequent Advisor

Re: build a string

.. i want add that if , for example is 1th of April , I need string ENDED: Sat Apr 1 and
not ENDED: Sat Apr 1 ( note position of numer one )

Caesar_3
Esteemed Contributor

Re: build a string

Hello!

I'm not so shure what you mean?
If you want to ptint this string it's like:
print "ENDED: Sat Apr 12"
If you want to take the date and format it
as you want you can use the "date" command
with parameter that spesify the format of
the output, check the man for the date
to see the parameters.

Caesar
Massimo Bianchi
Honored Contributor

Re: build a string

Hi Claudio,
try this:

DATE=$( date +"%a %b %e" )

STRING="ENDED: "$DATE

echo $STRING

Massimo

Tom Geudens
Honored Contributor

Re: build a string

Hi,
That would be
echo "ENDED: $(date +'%a %b %e')"
Regards,
Tom
A life ? Cool ! Where can I download one of those from ?
Andreas Voss
Honored Contributor

Re: build a string

Hi,

try this one:

echo "ENDED: $(date '+%a %b %d')"

Regards
Claudio_17
Frequent Advisor

Re: build a string

Sorry , I try explain better : the date is not a costant ; again , this string is what fbackup write in /var/adm/fbackupfiles/dates using -u option ; I want check this string to be absolutely sure fbackup terminated correctly ; so I need build a string every day . A bit problem is that when day is between 1-9 there are 2 blank spaces between the end on month ..
Dario_1
Trusted Contributor
Solution

Re: build a string

Hi:

Try this:

DATE=`date +'%a %b %e'`
STATUS="ENDED:"
STRING="$STATUS $DATE"

echo $STRING

Regards,

Dario
Massimo Bianchi
Honored Contributor

Re: build a string

Hi Claudio,
quoting from "man date"

%e Day of the month as a two-character decimal number with
leading space fill [" 1"-"31" ]. For example, 12.


so %e should fulfill your requirements !

HTH,
Massimo

James R. Ferguson
Acclaimed Contributor

Re: build a string

Hi Claudio:

If you want to align a day value like one as ' 1' and not '1' use a formatted print, thusly:

# printf "ENDED: %s %s %2d\n" $(date +'%a') $(date +'%b') $(date +'%d')

Regards!

...JRF...
Bill Douglass
Esteemed Contributor

Re: build a string

If you install the GNU date program, you can specify the date you want displayed with the -d option:


echo ENDED: `./date -d 4/1/2003 +"%a %b %_d"`

See the archive at

http://hpux.cs.utah.edu/hppd/hpux/Gnu/sh_utils-2.0/

Dario_1
Trusted Contributor

Re: build a string

Claudio:

Replace the %e for %d in my answer. This was taken from the date man pages.

%d Day of the month as a two-digit decimal number [01-31]. For
example, 12.

Regads,

Dario
Claudio_17
Frequent Advisor

Re: build a string

Thanks all ver much .

Sorry Tom ..for only 3 pts ; your was first resolutive answer .