Sponsored Content
Top Forums Shell Programming and Scripting Help with Display Shell Script for date Post 302640477 by kunwar on Monday 14th of May 2012 10:59:29 PM
Old 05-14-2012
Help with Display Shell Script for date

hi friends,
I am working on extracting data from sar logs for analysis.

What is want to do is insert the date. The way i am doing is incrementing the date if i see the hour gets reduced (i.e. from 23 hours to 00 hours). Somehow the script which i have made is not able to handle the logic w.r.t 0.
Can you please suggest where i am going wrong /provide alternate scripting suggestion?

Below is the source file
Code:
> cat tt1
00:52:32,disk2000,0.01,0.50,0,0,0.00,1.31
00:52:32,disk2001,0.00,0.50,0,0,0.00,0.53
00:52:32,disk2003,0.00,0.50,0,0,0.00,0.78
00:52:32,disk2008,0.02,0.50,0,0,0.00,5.85
01:01:59,disk30,2.57,14.58,8,125,38.78,11.19
01:01:59,disk50,2.96,13.54,9,131,36.71,11.47
01:01:59,disk745,0.00,0.50,0,0,0.00,0.66
01:01:59,disk746,0.02,0.50,0,0,0.00,10.58
01:01:59,disk747,0.02,0.50,0,0,0.00,9.47



What I want is below output:

Code:
09-05-12 00:52:32,disk2000,0.01,0.50,0,0,0.00,1.31
09-05-12 00:52:32,disk2001,0.00,0.50,0,0,0.00,0.53
09-05-12 00:52:32,disk2003,0.00,0.50,0,0,0.00,0.78
09-05-12 00:52:32,disk2008,0.02,0.50,0,0,0.00,5.85
10-05-12 01:01:59,disk30,2.57,14.58,8,125,38.78,11.19
10-05-12 01:01:59,disk50,2.96,13.54,9,131,36.71,11.47
10-05-12 01:01:59,disk745,0.00,0.50,0,0,0.00,0.66
10-05-12 01:01:59,disk746,0.02,0.50,0,0,0.00,10.58
10-05-12 01:01:59,disk747,0.02,0.50,0,0,0.00,9.47



What i am getting is:

Code:
> ksh a3
10-05-12 00:52:32,disk2000,0.01,0.50,0,0,0.00,1.31
10-05-12 00:52:32,disk2001,0.00,0.50,0,0,0.00,0.53
10-05-12 00:52:32,disk2003,0.00,0.50,0,0,0.00,0.78
10-05-12 00:52:32,disk2008,0.02,0.50,0,0,0.00,5.85
09-05-12 01:01:59,disk30,2.57,14.58,8,125,38.78,11.19
09-05-12 01:01:59,disk50,2.96,13.54,9,131,36.71,11.47
09-05-12 01:01:59,disk745,0.00,0.50,0,0,0.00,0.66
09-05-12 01:01:59,disk746,0.02,0.50,0,0,0.00,10.58
09-05-12 01:01:59,disk747,0.02,0.50,0,0,0.00,9.47



The content of my script is:

Code:
> cat a3
#!/usr/bin/ksh
d='05/09/12'
mm=${d%??????}
yy=${d#??????}
dd1=${d%???}
ddx=${dd1#???}
awk -v dd="$ddx" -v mm="$mm" -v yy="$yy" -F":" '{a=$1;} {print ($1 < $a && $a !=0)   ?  dd + 1 "-" mm "-" yy " " $0 : dd "-" mm "-" yy " " $0}'  tt1

I know my logic to input the date in the output is dirty , but atleast it should get me started Smilie..

Thanks,
Kunwar
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to display last login date/time?

I was wondering if anyone had a script that would display the last time a user logged into a particular machine. I know about the "last" command, but it gives too much info.... I just wanted to know the last time a user used his/her id. ANy help would be greatly appreciated. Ryan (3 Replies)
Discussion started by: ryaneverett5
3 Replies

2. UNIX for Dummies Questions & Answers

Shell Script Display?

I remember learning that there is a way to make a shell script display the script itself to standard output while the script is being executed but I can't find how to do that. Any pointers? (2 Replies)
Discussion started by: wmosley2
2 Replies

3. Shell Programming and Scripting

Specify a previous date as start date in shell script

Hi, I am trying to modify a script which accepts date in format dd/mm/yy. I am trying to modify the script so that it retrieves the date that was 15 days earlier from today as start date. Eg.if today is 05/09/2006, the script should retrieve 21/08/2006 as start date. Is there any script/code to... (2 Replies)
Discussion started by: ritzwan0
2 Replies

4. Shell Programming and Scripting

Past date display ( today - N) in shell

Hi, Any idea to get display of date - n ( n=1,2,3,4 etc) ? For example , dtoudt will easily execute by dtoudt -3 and result is >dtoudt -3 1234852529 Date 2009-2-17 time 14:35:29 day 47 How to get it display in 20090217 instead ? Maybe you have other suggestion to display date... (0 Replies)
Discussion started by: rauphelhunter
0 Replies

5. Shell Programming and Scripting

How to increment a user defined date value in the DATE format itself using shell script?

I need to increment a date value through shell script. Input value consist of start date and end date in DATE format of unix. For eg. I need increment a date value of 1/1/09 to 31/12/09 i.e for a whole yr. The output must look like 1/1/09 2/2/09 . . . 31/1/09 . . 1/2/09 . 28/2/09... (1 Reply)
Discussion started by: sunil087
1 Replies

6. Shell Programming and Scripting

Need help in Shell Script comparing todays date with Yesterday date from Sysdate

Hi, I want to compare today's date(DDMMYYYY) with yesterday(DDMMYYYY) from system date,if (today month = yesterday month) then execute alter query else do nothing. The above requirement i want in Shell script(KSH)... Can any one please help me? Double post, continued here. (0 Replies)
Discussion started by: kumarmsk1331
0 Replies

7. UNIX for Dummies Questions & Answers

How to write a shell script to Run it the from Date A to Date B?

Hi , How would i write a shell script to run the code from one date to another date EXample 2014-01-01 to 2014-02-28, can i any provide some clue on this (4 Replies)
Discussion started by: vikatakavi
4 Replies

8. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

9. Linux

How to calculate the quarter end date according to the current date in shell script?

Hi, My question is how to calculate the quarter end date according to the current date in shell script? (2 Replies)
Discussion started by: Divya_1234
2 Replies

10. UNIX for Beginners Questions & Answers

Compare Date to today's date in shell script

Hi Community! Following on from this code in another thread: #!/bin/bash file_string=`/bin/cat date.txt | /usr/bin/awk '{print $5,$4,$7,$6,$8}'` file_date=`/bin/date -d "$file_string"` file_epoch=`/bin/date -d "$file_string" +%s` now_epoch=`/bin/date +%s` if then #let... (2 Replies)
Discussion started by: Greenage
2 Replies
DATE(1) 						      General Commands Manual							   DATE(1)

NAME
date - print and set the date SYNOPSIS
date [-nu] [-d dst] [-t timezone] [yymmddhhmm [.ss] ] DESCRIPTION
If no arguments are given, the current date and time are printed. Providing an argument will set the desired date; only the superuser can set the date. The -d and -t flags set the kernel's values for daylight savings time and minutes west of GMT. If dst is non-zero, future calls to gettimeofday(2) will return a non-zero tz_dsttime. Timezone provides the number of minutes returned by future calls to gettimeof- day(2) in tz_minuteswest. The -u flag is used to display or set the date in GMT (universal) time. yy represents the last two digits of the year; the first mm is the month number; dd is the day number; hh is the hour number (24 hour system); the second mm is the minute num- ber; .ss is optional and represents the seconds. For example: date 8506131627 sets the date to June 13 1985, 4:27 PM. The year, month and day may be omitted; the default values will be the current ones. The system operates in GMT. Date takes care of the conversion to and from local standard and daylight-saving time. If timed(8) is running to synchronize the clocks of machines in a local area network, date sets the time globally on all those machines unless the -n option is given. FILES
/usr/adm/wtmp to record time-setting. In /usr/adm/messages, date records the name of the user setting the time. SEE ALSO
gettimeofday(2), utmp(5), timed(8), TSP: The Time Synchronization Protocol for UNIX 4.3BSD, R. Gusella and S. Zatti DIAGNOSTICS
Exit status is 0 on success, 1 on complete failure to set the date, and 2 on successfully setting the local date but failing globally. Occasionally, when timed synchronizes the time on many hosts, the setting of a new time value may require more than a few seconds. On these occasions, date prints: `Network time being set'. The message `Communication error with timed' occurs when the communication between date and timed fails. BUGS
The system attempts to keep the date in a format closely compatible with VMS. VMS, however, uses local time (rather than GMT) and does not understand daylight-saving time. Thus, if you use both UNIX and VMS, VMS will be running on GMT. 4th Berkeley Distribution March 24, 1987 DATE(1)
All times are GMT -4. The time now is 08:01 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy