The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Convert String to Date ORatjeuh Shell Programming and Scripting 2 05-06-2008 06:49 AM
Mutt - Word Document or Formatted text as a Message krsenkumar UNIX for Advanced & Expert Users 1 04-05-2008 11:10 AM
find formatted filename with date time dpath2o UNIX for Advanced & Expert Users 6 02-05-2008 11:20 PM
convert Julian date to calender date srikanthus2002 Shell Programming and Scripting 6 05-08-2007 06:27 AM
How do I convert unix text to to win text? nucca UNIX for Dummies Questions & Answers 1 06-25-2001 02:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-09-2007
osramos osramos is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Convert DATE string to a formatted text

Hi guys, i need your help.

I need to convert a date like this one 20071003071023 , to a formated date
like 20071003 07:10:23 .

Could this be possible ?

Regards,

Osramos
  #2 (permalink)  
Old 10-09-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Code:
# echo "20071003071023" | awk '{print substr($0,1,8)" "substr($0,9,2)":"substr($0,11,2)":"substr($0,13,2)}'
20071003 07:10:23
  #3 (permalink)  
Old 10-09-2007
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
Code:
echo 20071003071023 | sed 's/\(..\)\(..\)\(..\)$/ \1:\2:\3/'
  #4 (permalink)  
Old 10-10-2007
osramos osramos is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Converte DATE string to a formated text - Part2

Hello,

thanks to all who help me, but i make a mystake .

I've got this piece of file

APPLICATION GROUP_NAME MEMNAME ODATE STATUS START_TIME END_TIME


-------------------- -------------------- ------------------------------ ------ ---------------- -------------- --------------


AFT AFTSCMDIVD AFTDIVD1312A 071001 Ended OK 20071002041242 20071002041242

AFT AFTSCMDIVD AFTDIVD0115B 071002 Ended OK 20071003063253 20071003063303

and i want to convert to this :



APPLICATION GROUP_NAME MEMNAME ODATE STATUS START_TIME END_TIME


-------------------- -------------------- ------------------------------ ------ ---------------- -------------- --------------


AFT AFTSCMDIVD AFTDIVD1312A 071001 Ended OK 20071002 04:12:42 20071002 04:12:42

AFT AFTSCMDIVD AFTDIVD0115B 071002 Ended OK 20071003 06:32:53 20071003 06:33:03


like i've told before , all i need is to format the date and time, but i need to have also the file output with all de information.

Is it possible or is more complicated
  #5 (permalink)  
Old 10-10-2007
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,209
Have you tried the sed command I provided? It will format the last occurrence, you can easily extent that to cover the date in the second to last field.
  #6 (permalink)  
Old 10-10-2007
osramos osramos is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 21
Hi, yes i have tried with you sed command like this :

cat report_jobs_CTM.csv | awk '{print $7 $8}' |sed 's/\(..\)\(..\)\(..\)$/ \1:\2:\3/' > new.csv

but the the result was this:

EN D_:TI:ME
-------- --:--:--
2007100204124220071002 04:12:42
2007100204124820071002 04:12:48

Why i am doing wrong ?
  #7 (permalink)  
Old 10-10-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Code:
awk '{ 
     for(i=7;i<=8;i++) {
       $i=substr($i,1,8)" "substr($i,9,2)":"substr($i,11,2)":"substr($i,13,2)
     }
     {print}
}' "file"
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 07:45 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