Date capture & filter | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Date capture & filter

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 4 February 2014, 4:13 AM EST
Location: Bangalore, India
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
Date capture & filter

Dear All,

I am capturing system date and creating the file by using that time stamp, file is getting appended with checks of application & database check logs.

But when the date is in between 1 to 9 both inclusive, it appends a single space to file name but after 9th it works fine.


Code:
tmstmp=`date +%e%b%Y_%H%M%S`
file_name=Daily_Check"_"${tmstmp}.out

Output for the same is below:
Daily_Check_ 7Jan2013_124706.out
Daily_Check_26Jan2013_070036.out

Desired output is below:
Daily_Check_7Jan2013_124706.out
Daily_Check_26Jan2013_070036.out

Request you to help for the same.
Sponsored Links
    #2  
Old 01-31-2013
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 24 October 2014, 12:11 PM EDT
Location: India
Posts: 1,831
Thanks: 25
Thanked 525 Times in 504 Posts

Code:
tmstmp=`date +%e%b%Y_%H%M%S`
tmstmp=${tmstmp# }
file_name=Daily_Check"_"${tmstmp}.out

The Following User Says Thank You to balajesuri For This Useful Post:
pradeep84in (01-31-2013)
Sponsored Links
    #3  
Old 01-31-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 24 October 2014, 3:30 PM EDT
Location: Aachen, Germany
Posts: 4,425
Thanks: 73
Thanked 1,082 Times in 1,020 Posts
Use %d instead of %e to get the day zero-padded, or use %-e to rule out padding (may be misleading:
Code:
$ date +%-e%-m%Y -dtomorrow
122013

).
The Following User Says Thank You to RudiC For This Useful Post:
pradeep84in (01-31-2013)
    #4  
Old 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 4 February 2014, 4:13 AM EST
Location: Bangalore, India
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by balajesuri View Post
Code:
tmstmp=`date +%e%b%Y_%H%M%S`
tmstmp=${tmstmp# }
file_name=Daily_Check"_"${tmstmp}.out

Thanks your code works absolutely fine, can you explain what had happened here and how it had removed the blank space from the in between....
Sponsored Links
    #5  
Old 01-31-2013
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 22 October 2014, 8:12 PM EDT
Location: Galactic Empire
Posts: 3,387
Thanks: 235
Thanked 1,209 Times in 1,135 Posts
Refer string manipulation (link removed)
Sponsored Links
    #6  
Old 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 4 February 2014, 4:13 AM EST
Location: Bangalore, India
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by RudiC View Post
Use %d instead of %e to get the day zero-padded, or use %-e to rule out padding (may be misleading:
Code:
$ date +%-e%-m%Y -dtomorrow
122013

).

Thanks RudiC, I had used
Code:
%d

and it's giving the output by padding zero to it and it's keeping the lenght of the file name constant.

I tried to use
Code:
%-e

but it's not giving the desired output.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
PHPMaker 9 Help with Server Events & Filter vestport Web Programming 0 05-17-2012 01:27 AM
Need to capture dates between start date and end date Using perl. Nagaraja Akkiva Shell Programming and Scripting 6 07-21-2011 12:11 PM
Need to capture all dates between start date and End date. Nagaraja Akkiva Shell Programming and Scripting 5 05-16-2011 11:48 AM
filter input & outputs to another file user_prady Shell Programming and Scripting 1 11-05-2008 02:31 AM
Filter by modify date. millerdc Shell Programming and Scripting 2 07-29-2007 09:48 PM



All times are GMT -4. The time now is 12:14 AM.