Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-31-2013
Registered User
 
Join Date: Dec 2012
Location: Bangalore, India
Posts: 5
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
#! /bin/bash
 
Join Date: Apr 2009
Location: India
Posts: 1,570
Thanks: 14
Thanked 441 Times in 426 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
Location: Aachen, Germany
Posts: 1,908
Thanks: 25
Thanked 439 Times in 424 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
Registered User
 
Join Date: Dec 2012
Location: Bangalore, India
Posts: 5
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
Jedi Master
 
Join Date: Jan 2012
Location: Galactic Empire
Posts: 2,309
Thanks: 154
Thanked 738 Times in 710 Posts
Refer string manipulation
Sponsored Links
    #6  
Old 01-31-2013
Registered User
 
Join Date: Dec 2012
Location: Bangalore, India
Posts: 5
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
Reply

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 06:41 PM.