Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Date capture & filter

Shell Programming and Scripting


Closed    
 
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: 17 September 2016, 10:07 AM EDT
Location: Bengaluru / 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: 1 December 2016, 8:47 AM EST
Location: India
Posts: 1,966
Thanks: 30
Thanked 567 Times in 543 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 Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 3 December 2016, 2:05 PM EST
Location: Aachen, Germany
Posts: 9,896
Thanks: 198
Thanked 2,942 Times in 2,747 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 (02-01-2013)
    #4  
Old Unix and Linux 01-31-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 17 September 2016, 10:07 AM EDT
Location: Bengaluru / 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: 1 December 2016, 2:43 PM EST
Location: Galactic Empire
Posts: 3,529
Thanks: 248
Thanked 1,281 Times in 1,203 Posts
Refer string manipulation (link removed)
Sponsored Links
    #6  
Old Unix and Linux 02-01-2013
pradeep84in pradeep84in is offline
Registered User
 
Join Date: Dec 2012
Last Activity: 17 September 2016, 10:07 AM EDT
Location: Bengaluru / 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

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 02:27 AM
Need to capture dates between start date and end date Using perl. Nagaraja Akkiva Shell Programming and Scripting 6 07-21-2011 01:11 PM
Need to capture all dates between start date and End date. Nagaraja Akkiva Shell Programming and Scripting 5 05-16-2011 12:48 PM
filter input & outputs to another file user_prady Shell Programming and Scripting 1 11-05-2008 03:31 AM
Filter by modify date. millerdc Shell Programming and Scripting 2 07-29-2007 10:48 PM



All times are GMT -4. The time now is 03:39 PM.