## Solved: Date: Convert m to mm

Solved: Date: Convert m to mm
# 1
08-26-2013
Solved: Date: Convert m to mm

Hi all,

I've searched through the forum and can't find a thread specific to this question:

I have a CSV file with a date column, the dates I'm given from the original file look like: "m/dd/yyyy" (UNLESS it's a double digit month, like October, where it would then show up as "mm/dd/yyyy"). Is there an easy way where I could add a "0" to the "m" if the month has a single digit?

I know I can grab the column using awk, I just don't know how I can perform the if statement to add the "0" prefix to the month from the value I'd grab (which in this case, would by \$4 as far as awk is concerned). Any pointer in the right direction sure would be appreciated, if this is doable.

Thanks!
 mtucker6784 View Public Profile for mtucker6784 Find all posts by mtucker6784
# 2
08-26-2013
try awk -F, -vOFS=, '\$4 ~ /^.\//{\$4="0"\$4}1' input

This User Gave Thanks to neutronscott For This Post:
 neutronscott View Public Profile for neutronscott Visit neutronscott's homepage! Find all posts by neutronscott
# 3
08-26-2013
Neutron, that was perfect. Thanks so much, I sure appreciate your prompt response

Just out of curiosity, can you explain to me how that command knows to insert a 0 if the month isn't a double digit? I don't quite follow the logic in that statement. Thank you for your time.

Last edited by mtucker6784; 08-26-2013 at 04:18 PM.. Reason: Asking about clarification of statement---
 mtucker6784 View Public Profile for mtucker6784 Find all posts by mtucker6784
# 4
08-26-2013
The secret is here:

which means that field 4 begins (^) with any character (.) (i.e. a number) followed by a slash (escaped) (\/). If field 4 started with two digits, the match would fail.

This User Gave Thanks to Scott For This Post:
 Scott View Public Profile for Scott Find all posts by Scott
# 5
08-26-2013
Quote:
Originally Posted by mtucker6784
how that command knows to insert a 0 if the month isn't a double digit?
\$4 ~ Looks only for records number 4 which is the date part
/^.\// The action is only performed in string with one character followed by / char, that excludes 10/ (two digits followed by /)
\$4="0"\$4 if so, add an extra 0 to the record

Last edited by Aia; 08-26-2013 at 04:35 PM.. Reason: grammar correction
This User Gave Thanks to Aia For This Post:
 Aia View Public Profile for Aia Find all posts by Aia
# 6
08-26-2013
[Solved]

Aha! I see. Thank you, Scott. Is there a way to mark this thread as "solved"? Thanks!
 mtucker6784 View Public Profile for mtucker6784 Find all posts by mtucker6784
# 7
08-26-2013
Quote:
Originally Posted by mtucker6784
Is there a way to mark this thread as "solved"?
Done.
 Scott View Public Profile for Scott Find all posts by Scott

## Convert a date stored in a variable to epoch date

I am not able to pass date stored in a variable as an argument to date command. I get current date value for from_date and to_date #!/usr/bin/ksh set -x for s in server ; do ssh -T \$s <<-EOF from_date="12-Jan-2015 12:02:09" to_date="24-Jan-2015 13:02:09" echo \\$from_date echo...

## [Solved] Convert Row To column

Hi Folks, I am using db2 command -> db2 list tablespace show detail Tablespace ID = 10 Name = TSCDDHLMSUM Type = Database managed space Contents = All permanent data....

## Convert date arg to sql date

Doing a bcp load to sybase and need to convert datearg which comes in as 20130501 to 2013-05-01 which is the best way to do this

## [Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use...

## [Solved] need to convert decimal to integer

Using below command awk 'NR==FNR{A=\$1;next} {sum+=(\$2*A)}END{OFMT="%20f";print int(sum)}' Market.txt Product.txt answer:351770174.00000 how to convert this to 351770174. when i try with below command i am getting different result. awk 'NR==FNR{A=\$1;next}...

## Unable to convert date into no. using date -d +%s syntax in ksh shell

hi friends, I m trying to write a script which compares to dates. for this i am converting dates into no using synatx as below v2=`date | awk '{print \$2,\$3,\$4}'` v3=`date +%s -d "\$v2"` this syntax is working in bash shell ,but fails in ksh shell. please suggest on this.

## Convert date

If I pass the value in the form YYYY/MM/DD(20100719) how to convert in the form 19\/Jul\/2010

## convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52...

## convert Julian date to calender date

Hi, I have script in unix which creates a julian date like 126 or 127 I want convert this julian date into calender date ex : input 127 output 07/may/2007 or 07/05/2007 or 07/05/07 rgds srikanth