![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| a simple way of converting a date in seconds to normal date | travian | HP-UX | 2 | 11-23-2006 12:25 PM |
| converting text to csv format | gthokala | Shell Programming and Scripting | 13 | 06-09-2006 10:44 AM |
| converting PDF to text, rtf doc format | saurya_s | UNIX for Advanced & Expert Users | 1 | 04-23-2004 03:25 PM |
| Converting BMP to BM (or other unix format) | EJ =) | UNIX Desktop for Dummies Questions & Answers | 1 | 06-12-2002 08:42 AM |
| Converting the File Creation Date to a new format | barney_clough | UNIX for Dummies Questions & Answers | 1 | 06-12-2002 07:43 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
converting date format
Hi
Please anyone to help to write script to convert date to 'yyyy-mm-dd'(If column is date convert) because my file has large and lot of date colums. If file is small ,using awk command to achive. cat file1|awk 'BEGIN {FS=OFS='|'} {$1=substr($1,1,4)"-"substr($1,5,2)"-"substr($1,7,2);{$2=substr($2,1,4)"-"substr($2,5,2)"-"substr($2,7,2);print $0}' Thanks, MR |
|
||||
|
Quote:
Code:
awk 'BEGIN {FS=OFS="|"} {for (i=1;i<=NF;i++) if (length($i)==8) $i=substr($i,1,4)"-"substr($i,5,2)"-"substr($i,7,2);print }' file1
Last edited by danmero; 05-22-2008 at 12:24 AM.. |
|
||||
|
Hi danmero
How it can be handled If any othey colum that having length of 8 other than date columns ? (Is there any command to validate the date ).In that case it will take the columns data and convert to date format Thanks, MR |
|
||||
|
Yes, you can validate the date if you know the date range, here is a basic example:
Code:
awk 'BEGIN {FS=OFS="|"} {for (i=1;i<=NF;i++) if ($i ~ /[1-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9]/) $i=substr($i,1,4)"-"substr($i,5,2)"-"substr($i,7,2);print }' file1
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|