From: romy on
this one is pretty easy for most of you guys.

Format the date present in a csv file to date format MM/DD/YYYY

i/p : 1/1/1900
o/p : 01/01/1900 or 01-01-1900

i/p : 10/2/2009
o/p : 10/02/2009 or 10-02-2009

Thanks !
From: Barry Margolin on
In article
<4c2e7640-0766-4d49-8042-efb951e507b0(a)m31g2000yqd.googlegroups.com>,
romy <rave25(a)gmail.com> wrote:

> this one is pretty easy for most of you guys.
>
> Format the date present in a csv file to date format MM/DD/YYYY
>
> i/p : 1/1/1900
> o/p : 01/01/1900 or 01-01-1900
>
> i/p : 10/2/2009
> o/p : 10/02/2009 or 10-02-2009
>
> Thanks !

IFS=/
while read m d y
do
printf "%02d/%02d%04d\n" "$m" "$d" "$y"
done < input > output

--
Barry Margolin, barmar(a)alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Ed Morton on
On Feb 8, 7:23 pm, romy <rav...(a)gmail.com> wrote:
> this one is pretty easy for most of you guys.
>
> Format the date present in a csv file to date format MM/DD/YYYY
>
> i/p : 1/1/1900
> o/p : 01/01/1900 or 01-01-1900
>
>  i/p : 10/2/2009
> o/p : 10/02/2009 or 10-02-2009
>
> Thanks !

I have a feeling this will turn into a "thanks but my input REALLY
looks like this..." thread, but maybe this will be enough to get
started:

$ echo "1/1/1900" | awk -F'/' '{printf "%02d-%02d-%4d\n",$1,$2,$3}'
01-01-1900

Regards,

Ed.
From: romy on
On Feb 8, 8:57 pm, Ed Morton <mortons...(a)gmail.com> wrote:
> On Feb 8, 7:23 pm, romy <rav...(a)gmail.com> wrote:
>
> > this one is pretty easy for most of you guys.
>
> > Format the date present in a csv file to date format MM/DD/YYYY
>
> > i/p : 1/1/1900
> > o/p : 01/01/1900 or 01-01-1900
>
> >  i/p : 10/2/2009
> > o/p : 10/02/2009 or 10-02-2009
>
> > Thanks !
>
> I have a feeling this will turn into a "thanks but my input REALLY
> looks like this..." thread, but maybe this will be enough to get
> started:
>
> $ echo "1/1/1900" | awk -F'/' '{printf "%02d-%02d-%4d\n",$1,$2,$3}'
> 01-01-1900
>
> Regards,
>
>      Ed.

@Ed. Thanks much ! Nops this is what I needed. You rock !!
From: Phred Phungus on
Ed Morton wrote:
> On Feb 8, 7:23 pm, romy <rav...(a)gmail.com> wrote:
>> this one is pretty easy for most of you guys.
>>
>> Format the date present in a csv file to date format MM/DD/YYYY
>>
>> i/p : 1/1/1900
>> o/p : 01/01/1900 or 01-01-1900
>>
>> i/p : 10/2/2009
>> o/p : 10/02/2009 or 10-02-2009
>>
>> Thanks !
>
> I have a feeling this will turn into a "thanks but my input REALLY
> looks like this..." thread, but maybe this will be enough to get
> started:
>
> $ echo "1/1/1900" | awk -F'/' '{printf "%02d-%02d-%4d\n",$1,$2,$3}'
> 01-01-1900

I'm glad to see this post as I was reading up on perl, and awk is
mentioned more than once. I was nonplussed when I looked in the
reference for functions not to find it. I gathered that its
functionality had been incorporated into perl in a very central way.

http://www.opengroup.org/onlinepubs/009695399/utilities/awk.html

Apparently the -F does this:

Define the input field separator to be the extended regular expression ERE

So the -F'/' says split on the slash. I recognize the formats,
conversions and variables in the printf, but what's person to think of
the whole '{ ... }' syntax?
--
fred