LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replace the nth column date as MM/DD/YYYY (https://www.linuxquestions.org/questions/linux-newbie-8/replace-the-nth-column-date-as-mm-dd-yyyy-4175421808/)

anshaa 08-13-2012 02:51 AM

replace the nth column date as MM/DD/YYYY
 
Hi,

I need some unix command to replace the following thing.

cat test.dat


1234|test|8/19/2009||test
1234|test|8/9/09|8/21/2009|test
1234|test||8/1/09|test

after processing


1234|test|08/19/2009||test
1234|test|08/09/2009|08/21/2009|test
1234|test||08/01/2009|test

anshaa 08-13-2012 04:25 AM

nawk '{
for(i=3;i<=4;i++)
if((n=split($i,a,"/"))==3)
$i=sprintf("%02d/%02d/%04d",a[1],a[2],a[3])
}1' FS=\| OFS=\| infile


All times are GMT -5. The time now is 08:08 AM.