The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
parsing string in c phani_sree High Level Programming 3 10-24-2007 03:54 AM
parsing url string vanitham Shell Programming and Scripting 5 10-22-2007 06:48 AM
Need help on parsing string magnacrazy Shell Programming and Scripting 13 03-31-2007 04:54 AM
Parsing string rolex.mp UNIX for Dummies Questions & Answers 3 02-20-2007 01:28 PM
Need help parsing a string achieve Shell Programming and Scripting 6 09-14-2006 12:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-17-2008
martyb555 martyb555 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
Date parsing into string, help!

I have a file that was created yesterday that I want to access...
daily.log2008-02-16

I am using...
curr_time=`date +"%Y %m %d"`
yesterday=`./datecalc.ksh -a $curr_time - 1`

the value for yesterday is now "2008 2 16"

in ksh, how do I transform the string "2008 2 16" into "2008-02-16"
  #2 (permalink)  
Old 02-17-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431

Code:
printf "%d-%02ld-%d" 2008 2 16

  #3 (permalink)  
Old 02-17-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
i.e. same sort of thing as:

Code:
echo "2008 2 16" | awk '{printf("%d-%02ld-%d",$1,$2,$3)}'

  #4 (permalink)  
Old 02-17-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,439
Everything in one line:

Code:
yesterday=`./datecalc.ksh -a $curr_time - 1 | awk '{print $1"-"$2"-"$3}'`

  #5 (permalink)  
Old 02-17-2008
martyb555 martyb555 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 4
THANK YOU for your help
  #6 (permalink)  
Old 02-17-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,555

Code:
# echo "2008 2 16" | tr ' ' '-'
2008-2-16

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0