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
help reformat data with awk climbak Shell Programming and Scripting 4 05-30-2008 03:17 PM
how to reformat a hard disk mr_balodoy SUN Solaris 14 08-22-2007 03:29 AM
Reformat Crontab file alnita Shell Programming and Scripting 1 04-11-2007 03:28 AM
Date Reformat F-1 UNIX for Dummies Questions & Answers 2 04-25-2006 04:32 PM
reformat the file CamTu Shell Programming and Scripting 3 03-09-2005 05:01 PM

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 06-04-2008
mondrar mondrar is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
reformat date, awk and sed

The command below is getting me the output I need.
awk -F"," ' {
if ($6 = 475) print "@@"$3 " " "0000" $10 "0" $1 "00000000" $8}' ${DIR1}${TMPFILE1} | sed -e 's/@@1//g' > ${DIR2}${TPRFILE}

Output:
900018732 00004961160200805160000000073719

Now I need to incorporate this sed command to reformat the date to mmddyy:
sed 's/^\(..\)\(..\)\(..\)\(..\)$/\3\4\2/'

Any ideas...
  #2 (permalink)  
Old 06-04-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Like this?
Code:
echo '900018732 00004961200200805160000000073719'| sed -e 's/.*\(200.\{5\}\)00000000.*/\1/g' -e 's/^..\(..\)\(..\)\(..\)/\2\3\1/g'
051608
  #3 (permalink)  
Old 06-04-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,428
Quote:
Originally Posted by mondrar View Post
The command below is getting me the output I need.....
Any ideas...
Please provide sample data.
  #4 (permalink)  
Old 06-05-2008
mondrar mondrar is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
Thanks, that works, but what I really want to do is reformat the date in its current position, and leave all the text around it the same.

Is this possible, or am I confusing.
  #5 (permalink)  
Old 06-05-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Code:
 echo '900018732 00004961200200805160000000073719'| sed -e 's/\(.*\)20\(08\)\(....\)\(.*\)/\1\3\2\4/g'
  #6 (permalink)  
Old 06-05-2008
mondrar mondrar is offline
Registered User
  
 

Join Date: Jun 2008
Posts: 3
I was able to get it done, the long way. Yes, I know, it looks funny.

awk -F"," '{ if ($6 = 475) print $1 "," "@@"$3 "," $6 "," $10 "," $8}' ${DIR1}${INFILE} | sed -e 's/.*\(200.\{5\}\)00000000.*/\1/g' -e 's/^..\(..\)\(..\)\(..\)/\2\3\1/g' | sed -e 's/@@1//g' | sed -e 's/\.//g' | awk -F"," ' { print $2 " " "0000" $4 "0" $1 "00000000" $5}' > ${DIR2}${TPRFILE}
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 08:11 AM.


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