HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell Scripting..
Operating System - HP-UX
1835088
Members
1980
Online
110073
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-22-2001 08:09 PM
08-22-2001 08:09 PM
Shell Scripting..
How I can convert 234 to mmddyy format??
date +%j
234
234 is 22nd Aug....How I can convert that and display in 082201 format.....I know we can do date +%m%d%y to get that format..But my script is giving output 234 and I want to convert that to mmddyy format??
date +%j
234
234 is 22nd Aug....How I can convert that and display in 082201 format.....I know we can do date +%m%d%y to get that format..But my script is giving output 234 and I want to convert that to mmddyy format??
How to analyze HPMC Chassis codes???
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2001 08:40 PM
08-22-2001 08:40 PM
Re: Shell Scripting..
I am not sure if date command will allow us to convert the string back to your Aug 22 format. But there is a crude way of doing it using shell script. YOu need to make a table like this
DEC:334
NOV:304
OCT:273
....
FEB:31
JAN:0
let's call it daytable
Let's store your string in a variable $STR
This program will convert your string to month and day
for i in `cat daytable`
do
MON=`echo $i|awk '{FS=":";print $1}'`
DAY=`echo $i|awk '{FS=":";print $2}'`
if [ $STR -ge $DAY ]
then
echo STR is $STR Day is $DAY
MYDAYS=`echo $STR - $DAY |bc`
echo "$MON - $MYDAYS"
exit
fi
done
This will work only for this year. You need to change the values if you want for other years
-Sri
DEC:334
NOV:304
OCT:273
....
FEB:31
JAN:0
let's call it daytable
Let's store your string in a variable $STR
This program will convert your string to month and day
for i in `cat daytable`
do
MON=`echo $i|awk '{FS=":";print $1}'`
DAY=`echo $i|awk '{FS=":";print $2}'`
if [ $STR -ge $DAY ]
then
echo STR is $STR Day is $DAY
MYDAYS=`echo $STR - $DAY |bc`
echo "$MON - $MYDAYS"
exit
fi
done
This will work only for this year. You need to change the values if you want for other years
-Sri
You may be disappointed if you fail, but you are doomed if you don't try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2001 12:14 AM
08-23-2001 12:14 AM
Re: Shell Scripting..
Hi,
Here's a perl script to do it, uses 2 arguments, day-of-year and year (default - this year), e.g.
# doy2time.pl 40 1983
09-02-1983
# doy2time.pl 269
26-09-2001
========================================
#!/opt/perl5/bin/perl
if ( $#ARGV eq 0 ) {
$year=1900+(localtime)[5];
}
else {
$year=$ARGV[1];
}
$doy=$ARGV[0];
$numdays=-1;
for ( $y=1970 ; $y < $year ; $y++ ) {
$numdays+=365;
$rem=$y%4;
$numdays+=1 if ( $rem == 0 ) ;
}
$numdays+=$doy;
$numdays*=24*3600;
($d,$m)=(localtime($numdays))[3,4];
printf ("%02d-%02d-%04d\n",$d,$m+1,$year);
===========================================
Rgds, Robin.
Here's a perl script to do it, uses 2 arguments, day-of-year and year (default - this year), e.g.
# doy2time.pl 40 1983
09-02-1983
# doy2time.pl 269
26-09-2001
========================================
#!/opt/perl5/bin/perl
if ( $#ARGV eq 0 ) {
$year=1900+(localtime)[5];
}
else {
$year=$ARGV[1];
}
$doy=$ARGV[0];
$numdays=-1;
for ( $y=1970 ; $y < $year ; $y++ ) {
$numdays+=365;
$rem=$y%4;
$numdays+=1 if ( $rem == 0 ) ;
}
$numdays+=$doy;
$numdays*=24*3600;
($d,$m)=(localtime($numdays))[3,4];
printf ("%02d-%02d-%04d\n",$d,$m+1,$year);
===========================================
Rgds, Robin.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP