Operating System - HP-UX
1829102 Members
2374 Online
109986 Solutions
New Discussion

How can i view the space in a date when is from 01 to 09?

 
SOLVED
Go to solution
Manuales
Super Advisor

How can i view the space in a date when is from 01 to 09?

Hi ...
When i run ls -lrt date appears with a two spaces between "Jun" and "1"

australia:user1> ls -rlt
total 20
-rw-r--r-- 1 uno sapsys 992 Jun 1 13:25 message_error_server.txt
-rw-r--r-- 1 uno sapsys 147 Jun 1 13:25 message_error

If i run dia=`date "+%b %d"` appears
Jun 01

how can i use date command to show:
Jun 1 #two spaces between Jun and 1

or, how can i do to appear it?
I do something like this one

but it do not work.
dia=`date | cut -c5-10` # do not respect the spaces ...

Help please !!
Manuales.
24 REPLIES 24
OldSchool
Honored Contributor
Solution

Re: How can i view the space in a date when is from 01 to 09?

How about the following:

da1=`date +'%b %d' | sed 's/ 0/ /'`

??
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Manuales:

Well, you could filter the silly thing:

# date "+%b %d"|perl -pe 's/(...)0(\d)/$1 $2/'

...that's a space (blank) between $1 and $2.

...(or) if you if you don't care if there is only one space between the month and the day, use:

# date "+%b %0d"

Regards!

...JRF...
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

sorry ... that did not work !!!
Help please ..!!!!!
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

James, i'm going to check it ... let me please ...
Joseph C. Denman
Honored Contributor

Re: How can i view the space in a date when is from 01 to 09?

I'm still a little confused (Normal day) as to what you are attempting????

...jcd...
If I had only read the instructions first??
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

James, second worked but i need to keep this value into a variable, when i see what is the value of this variable the space is not there !!! :'( ....

1.- australia:user1> date "+%b %0d"
Jun 1
2.- australia:user1> date "+%b %d"|perl -pe 's/(...)0(\d)/$1 $2/'
Jun 1
3.- australia:user1> dia=`date "+%b %d"|perl -pe 's/(...)0(\d)/$1 $2/'`
4.- australia:user1> echo $dia
Jun 1
australia:user1>
how can i do to maintain the space?

Thanks ....
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi (again) Manuales:

Either the 'sed' or the 'perl' will work. The 'sed' solution is shorter and cheaper.

Your problems is (probably) that you did:

# da1=`date +'%b %d' | sed 's/ 0/ /'`
# echo ${da1} #...wrong!
# echo "${da1}" #...correct!!!

Regards!

...JRF...
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

I'm attaching you how it saw the space, into this portal either you can see the space .....

please , look file at attached.
OldSchool
Honored Contributor

Re: How can i view the space in a date when is from 01 to 09?

>> sorry ... that did not work !!!
>> Help please ..!!!!!

Don't know who that was for. attached is a script that demonstrates the sed option works.....

Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

I'm attaching you how it saw the space, into this portal either you can see the space .....

please , look file at attached.
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Manuales:

Oh, splat! Now I remember! Use this for space-fill. See the good-old-reliable manpages for 'date':

# date +'%b %e'

...no filter necessary!

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: How can i view the space in a date when is from 01 to 09?

lt09:/home/merijn 108 > perl -MDate::Manip -le'print scalar UnixDate"today","%b %e"'
Jun 1
lt09:/home/merijn 109 > perl -MDate::Calc=Month_to_Text -le'@t=localtime;printf"%s %2d\n",Month_to_Text(++$t[4]),$t[3]'
June 1
lt09:/home/merijn 110 >

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: How can i view the space in a date when is from 01 to 09?

Within 10 seconds :)
We both came up with %e
How wonderful this forum is ...

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Merijn:

Ah, yes, but how wonderful you taught me to *first* think Perl! :-))

Regards!

...JRF...
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

I'm agree with you procura !!!!
thanks a lot to all !!!!

and ....

o.k. that's works:
australia:user1> da1=`date +'%b %d' | sed 's/ 0/ /'`
australia1:user1> echo "${da1}"
Jun 1 #here there is a space ...



and .. do i use correctly the following sentence with if? i mean, using variable wich contains the value date above asked:

if [[ ! -n `cat ${logftp}_out | grep "${dia}" | grep "$file_delivered"` ]]


thanks....
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Manuales:

You wrote:

# if [[ ! -n `cat ${logftp}_out | grep "${dia}" | grep "$file_delivered"` ]] ...

This creates extra processes. 'grep' reads a file directly, so:

# if [[ ! -n `grep -e ${dia} -e "$file_delivered ${logftp}_out ]] ...

...should work...

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Manuales:

You wrote:

# if [[ ! -n `cat ${logftp}_out | grep "${dia}" | grep "$file_delivered"` ]] ...

This creates extra processes. 'grep' reads a file directly, so:

# if [[ ! -n "`grep -e ${dia} -e $file_delivered ${logftp}_out`" ]] ...

...should work...

Regards!

...JRF...
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

James .. could you tell me what is here "perl" command ..

dia=`date "+%b %d"|perl -pe 's/(...)0(\d)/$1 $2/'`

is the software installed here? how can i verify it .. or is a command like awk or something like that??



James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Manuales:

Perl is installed with HP-UX although more recent ports are available. Merijn offers at his own site a tremendous plethora!

http://mirrors.develooper.com/hpux/

You can get a reasonablly update binary for HP-UX here, too:

http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL

Generally, Perl is installed in '/opt/perl/bin/perl' and a symbolic link from 'usr/bin/perl' is created to point to it.

# perl -v

...returns your version. You should have at least 5.8.x

Perl is much more than 'awk' or 'sed' although it borrows from both plus the C language:

http://www.perl.org/about.html

Regards!

...JRF...
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

thanks ...

you know, i have the following error in cron log:

putmthly_test.sh[56]: perl: not found.

but it worked !!!! any way do not worry , the important is that worked, why ? i do not why ...!!!

thanks for explanation ...

my server has: This is perl, version 5.005_02 built for PA-RISC1.1


why could have worked with above error shown?

Thanks.
James R. Ferguson
Acclaimed Contributor

Re: How can i view the space in a date when is from 01 to 09?

Hi Manuales:

With regard to your crontab --- remember that by default, the environment provided by 'cron' has a default PATH of '/usr/bin' and '/usr/sbin' only.

Given that Perl is usually installed in '/opt' with a symbolic link from '/usr/bin' unless you have that link, this would fail for that reason.

More likely, thought, is that the Perl executable you have resides in '/usr/contrib/bin/perl' which is an *old* version provided by HP-UX. Since your PATH probably contains that, running 'perl...' from a normal shell finds the executable.

Regards!

...JRF...
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

THANKS ALL OF YOU !!!!

REALLY, REALLY, THANKS !!!

Manuales.
Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

Hi ... sory .. .and now .. how can i do to see file with next sintax:

i want see Jun 02 instead of Jun (space)2

Thanks .

Manuales
Super Advisor

Re: How can i view the space in a date when is from 01 to 09?

I got it :


dia=`date +'%b %d'`

Tanks ..