Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Date capture & filter

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 8 April 2015, 10:51 PM EDT
Location: Kolkata, India
Posts: 11
Thanks: 4
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 Unix and Linux 01-31-2013
balajesuri's Unix or Linux Image
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 21 May 2015, 12:48 AM EDT
Location: India
Posts: 1,886
Thanks: 27
Thanked 539 Times in 516 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 Unix and Linux 01-31-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 22 May 2015, 5:26 AM EDT
Location: Aachen, Germany
Posts: 5,945
Thanks: 105
Thanked 1,587 Times in 1,491 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 Unix and Linux 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 8 April 2015, 10:51 PM EDT
Location: Kolkata, India
Posts: 11
Thanks: 4
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 Unix and Linux 01-31-2013
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 21 May 2015, 5:13 PM EDT
Location: Galactic Empire
Posts: 3,402
Thanks: 240
Thanked 1,216 Times in 1,142 Posts
Refer string manipulation (link removed)
Sponsored Links
    #6  
Old Unix and Linux 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 8 April 2015, 10:51 PM EDT
Location: Kolkata, India
Posts: 11
Thanks: 4
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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 05:59 AM.