- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Help needed
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
12-19-2014 03:36 PM
12-19-2014 03:36 PM
Hello,
i'm writing a script but i need your support as follow:
I have a file as follow :
20141219232332 QL-KHARKANIA-3G--01 warning
20141219102332 QL-KHARKANIA-3G-03 warning
20141219152334 QL-KHARKANIA-3G-02 warning
20141219112341 Kafr-Hamam-3G-01 warning
20141219162341 Kafr-Hamam-3G-02 warning
20141219202341 Kafr-Hamam-3G-03 warning
............................
...........................
..........................etc
the first coloum is represent the date but in string formate(year month day hour min second) and in UTC time and in need to add 2 hour to meet my local time...what i need from you that can any help on change this formate to be in format of (year/Month/day hour/min/sec) and replace it in the same location and to be my loacal time as add 2 hour to itas follow.
2014/12/20 01:23:32 QL-KHARKANIA-3G--01 warning
2014/12/19 12:23:32 QL-KHARKANIA-3G-03 warning
2014/12/19 17:23:34 QL-KHARKANIA-3G-02 warning
2014/12/19 13:23:41 Kafr-Hamam-3G-01 warning
2014/12/19 19:23:41 Kafr-Hamam-3G-02 warning
2014/12/19 22:23:41 Kafr-Hamam-3G-03 warning
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2014 03:53 PM
12-19-2014 03:53 PM
Re: Help needed
the script is under HP-UX not linux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-20-2014 08:36 AM - edited 12-21-2014 01:48 PM
12-20-2014 08:36 AM - edited 12-21-2014 01:48 PM
SolutionSomething like:
awk '
BEGIN {
days[1] = 31; days[2] = 28; days[3] = 31; days[4] = 30
days[5] = 31; days[6] = 30; days[7] = 31; days[8] = 31
days[9] = 30; days[10] = 31; days[11] = 30; days[12] = 31
}
{
ts = substr($0, 1, 14)
rest = substr($0, 15)
yy = substr(ts, 1, 4)
mm = substr(ts, 5, 2)
dd = substr(ts, 7, 2)
hh = substr(ts, 9, 2)
MM = substr(ts, 11, 2)
ss = substr(ts, 13, 2)
# Add 2 hours for local time
hh += 2
# Handle carries
if (hh >= 24) {
hh -= 24
++dd
# convert mm to number
mm += 0
dom = days[mm]
# Handle leap years
if (mm == 2 && yy % 4 == 0 && (yy % 100 != 0 || yy % 400 == 0)) {
# print "leap year:", yy
dom = 29
}
if (dd > dom) {
dd = 1
++mm
if (mm > 12) {
mm = 1
++yy
}
}
}
printf "%d/%.2d/%.2d %.2d:%.2d:%2d%s\n", yy, mm, dd, hh, MM, ss, rest
}' input-file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2014 06:08 AM
12-21-2014 06:08 AM
Re: Help needed (formating timestamp)
dude...you are brilliant it working....as expected...thanks and appreicate...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2014 01:53 PM
12-21-2014 01:53 PM
Re: Help needed (formating timestamp)
>thanks and appreciate
If you're happy with the answer, please click on the kudos thumbs-up.
I noticed I made a mistake in the leap year check for 2000 and next in 2400. It should be:
if (mm == 2 && yy % 4 == 0 && (yy % 100 != 0 || yy % 400 == 0)) {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2014 02:33 PM
12-21-2014 02:33 PM
Re: Help needed (formating timestamp)
>>I noticed I made a mistake in the leap year check for 2000 and next in 2400
Really?! You're that concerned about the leap year check for the year 2400? ;)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2014 08:35 PM - edited 12-21-2014 08:37 PM
12-21-2014 08:35 PM - edited 12-21-2014 08:37 PM
Re: Help needed (formating timestamp)
>You're that concerned about the leap year check for the year 2400? ;)
Having worked on Y2K and Y2K7, I didn't want to be hung in effigy nor kicked out of those new-fangled flying cars. :-)