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
Locale::Codes::LangFam(3pm)				 Perl Programmers Reference Guide			       Locale::Codes::LangFam(3pm)

NAME
Locale::Codes::LangFam - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangFam; $lext = code2langfam('apa'); # $lext gets 'Apache languages' $code = langfam2code('Apache languages'); # $code gets 'apa' @codes = all_langfam_codes(); @names = all_langfam_names(); DESCRIPTION
The "Locale::Codes::LangFam" module provides access to standard codes used for identifying language families, such as those as defined in ISO 639-5. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default ISO 639-5 language family codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language families. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langfam('apa','alpha'); $lext = code2langfam('apa',LOCALE_LANGFAM_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from ISO 639-5 such as 'apa' for Apache languages. This is the default code set. ROUTINES
code2langfam ( CODE [,CODESET] ) langfam2code ( NAME [,CODESET] ) langfam_code2code ( CODE ,CODESET ,CODESET2 ) all_langfam_codes ( [CODESET] ) all_langfam_names ( [CODESET] ) Locale::Codes::LangFam::rename_langfam ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangFam::add_langfam ( CODE ,NAME [,CODESET] ) Locale::Codes::LangFam::delete_langfam ( CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_alias ( NAME ,NEW_NAME ) Locale::Codes::LangFam::delete_langfam_alias ( NAME ) Locale::Codes::LangFam::rename_langfam_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::add_langfam_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangFam::delete_langfam_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.loc.gov/standards/iso639-5/id.php ISO 639-5 . AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2012 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.2 2012-10-11 Locale::Codes::LangFam(3pm)
All times are GMT -4. The time now is 11:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy