Solved Unix Sed Command

June 17, 2011 at 04:42:50
Specs: Windows XP
Hi,

I have a "|" file with 5 dates in the format of mm/dd/yy, I only need to change the date format in 2 fields only (field1 and 3) to mmddccyy, here's the command I'm using:
awk ' BEGIN { OFS=FS="|" }
{
sed '(s/\(..\)\/\(..\)\/\(..\)/\1\220\3/)' $1, $3)
print $0
} ' dd.txt > out.txt

that command is not working for me, can you help.

here's an example: 01/05/10|02/05/44|05/06/11|10/12/77|03/12/44|

need the output to look like: 01052010|02/05/44|05062011|10/12/77|03/12/44|

Thank you


See More: Unix Sed Command

Report •

#1
June 17, 2011 at 07:24:54
awk does not support calling sed like you are trying to do.

The internal awk gsub function should do it:

#!/bin/ksh

awk ' BEGIN { OFS=FS="|" }
{
gsub("\/","",$1)
gsub("\/","",$3)
print $0
} ' data.txt


Report •

#2
June 20, 2011 at 04:57:05
Thanks for the quick response but this command does not insert the century before the yy. I need the date to look like 10052011.

Thanks


Report •

#3
June 20, 2011 at 07:24:49
✔ Best Answer
Sorry, missed the century requirement ....

#!/bin/ksh

awk ' BEGIN { OFS=FS="|" }
{
sub("\/","",$1)
sub("\/","",$3)
sub("\/","20",$1)
sub("\/","20",$3)
print $0
} ' data.txt


Report •

Related Solutions

#4
June 20, 2011 at 10:23:23
Thanks for all your help, I only been doing this for 3 months now, no training or classes. Hopefully one day I'll be as good.

Thanks again.


Report •

Ask Question