- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Scripting Question: date related ,
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
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
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
08-02-2012 08:52 AM
08-02-2012 08:52 AM
Hi All,
The script was working well From July 20th untill July 31st , but returned error after August 1st.
The script is matching files with the date stamp DS="date +%b%e%Y"
ls -l | grep $DS
But now it is not working as there is a space came in the value of $DS since August 1 2012.
Now it is returning a white space before the day, : thats the problem:
$ date +%b%e%Y
Aug 22012 ### See there is a white space before 2 #[Since the day is one digit , 2nd August]
- Earlier for "July 31st" it was returning like this: [ it was GOOD as no space in between ]
$ date +%b%e%Y
Jul312012
The output should be like this:
Aug022012 ## See 02 is there, instead of just " 2" .
Experts your help please, how to get the output without the white space but a zero instead of the white space.
Thanks in advance.
Solved! Go to Solution.
- Tags:
- date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 08:58 AM
08-02-2012 08:58 AM
Re: Scripting Question: date related ,
The date format you are seeing from the 'ls' command is the standard HP-UX format. If the day is a single-digit day, then there are 2 spaces between the Month and the day.
I do not know if there is a way to change the date format without some other scripting to remove extraneous spaces.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 12:25 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 01:34 PM
08-02-2012 01:34 PM
Re: Scripting Question: date related ,
All,
Sorry its my bad,
The filenames are having date stamp within the filename ,so $DS isl trying to match it,
here are the filenames :
$ ls -lrt
-rwxrwxrwx 1 oracle dba 9338001 Jul 31 16:05 ortle.txt.Jul3120121605
-rwxrwxrwx 1 oracle dba 50979785 Jul 31 16:23 ormpe.txt.Jul3120121623
-rwxrwxrwx 1 oracle dba 9357787 Aug 1 16:05 ortle.txt.Aug0120121605
-rwxrwxrwx 1 oracle dba 50912248 Aug 1 16:27 ormpe.txt.Aug0120121628
#--------------------------------------------------------------------------------------------------------------------
Thanks you in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 01:39 PM
08-02-2012 01:39 PM
Re: Scripting Question: date related ,
Steven,
Thanks much , it works with sed,
$ date +%b%e%Y | sed -e 's/ /0/'
Aug022012
However the question is: when the day will be more than 9,
As there is no white space when the day goes more than 9, so it will work fine too I guess.
Thanks again,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 01:58 PM - edited 08-02-2012 01:58 PM
08-02-2012 01:58 PM - edited 08-02-2012 01:58 PM
Re: Scripting Question: date related
A better fix is to look at ls.cat and look at the format:
$ dumpmsg /usr/lib/nls/msg/C/ls.cat | grep -e 11 -e 12
11 %b %2d %Y
12 %b %2d %H:%M
So for the American nerd locale, you should use the following in your date string:
date +"%b %2d"
>I do not know if there is a way to change the date format without some other scripting to remove extraneous spaces.
Simply make a copy of ls.cat with the changes you want.
Consult the tag cloud:
http://h30499.www3.hp.com/t5/tag/ls.cat/tg-p
>The filenames are having date stamp within the filename
Then change to a different format:
$ date "+%b %02d"
Aug 02
(Which matches what Steven said but more complex. ;-)
- Tags:
- ls.cat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 02:50 PM
08-02-2012 02:50 PM
Re: Scripting Question: date related
Dennis thanks...
Patrick ,Steven thanks..
All sorry for confusion.
I am trying to match the file name, not based on date and time stamp of ls -l output,
I am trying to match the last column (the file name , which is generating everyday with eachdays date-time stamp by another script that code I dont know, and the filename having the data-time stamp).
So I tried to match DS=`date "+%b%e%Y" [ produces: "Jul312012 or Aug 12012" ] , it was found producing one white space from August, if day is 1 to 9. it worked day 20th when I first wrote the script, untill 31st July. But after Aug 1 didnot work.
I found this today after I checked more example, after posted in to the forum:
DS=`date "+%b%d%Y" # [ producing correct: Aug022012" ]
[I should have taken : date "+%b%d%Y" in first attemp. Dont know how I missed it.]
Example:
$ DS=`date "+%b%d%Y" :
FILES: in /dir1/
....
...
-rwxrwxrwx 1 oracle dba 9338001 Jul 31 16:05 ortle.txt.Jul3120121605
-rwxrwxrwx 1 oracle dba 50979785 Jul 31 16:23 ormpe.txt.Jul3120121623
-rwxrwxrwx 1 oracle dba 9357787 Aug 1 16:05 ortle.txt.Aug0120121605
-rwxrwxrwx 1 oracle dba 50912248 Aug 1 16:27 ormpe.txt.Aug0120121628
-rwxrwxrwx 1 oracle dba 9457785 Aug 2 16:05 ortle.txt.Aug0220121605
-rwxrwxrwx 1 oracle dba 52912249 Aug 2 16:27 ormpe.txt.Aug0220121628
I want to match only last two files of current day (Aug 02, today)
# ls -l /dir1 | grep $DS
-rwxrwxrwx 1 oracle dba 9457785 Aug 2 16:05 ortle.txt.Aug0220121605
-rwxrwxrwx 1 oracle dba 52912249 Aug 2 16:27 ormpe.txt.Aug0220121628
#----
Here is the difference:
-------------------
# date "+%b%e%Y"
Aug 22012
# date "+%b%d%Y" #[OK]
Aug022012
------------------
It works ok with the 2nd one, i.e # date "+%b%d%Y" .
Thanks to all who responded. Kudos.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2012 09:59 PM
08-02-2012 09:59 PM
Re: Scripting Question: date related
>Thanks to all who responded. Kudos.
Besides Kudos, you might want to mark one of them as the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2012 02:11 PM
08-03-2012 02:11 PM
Re: Scripting Question: date related
Dennis,
I am confused about the below syntax you have mentioned, it is producing white space,
my objective to eliminate white space, as grep was resulting error,
>>
Then change to a different format:
$ date "+%b %02d"
$ date "+%b %02d"
Aug 03
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2012 03:33 PM
08-03-2012 03:33 PM
Re: Scripting Question: date related
>I am confused about the below syntax you have mentioned, it is producing white space
Sorry, that was when I thought you wanted the ll(1) output to have two digits and no extra space.
So you want what Steven had: date "+%b%d"