script for month conversion in numeric format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script for month conversion in numeric format
# 1  
Old 10-28-2009
script for month conversion in numeric format

Hi Experts,

How to convert months into numeric format with the help of some script:

Suppose I want:
" Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sept | Oct | Nov | Dec "

to be converted as :

" 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 "



Thanks in advance.
# 2  
Old 10-28-2009
Code:
echo " 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 "

Is there a point to this?
# 3  
Old 10-29-2009
you can use this awk script..
where MM is variable to which you pass your month name...
Code:
awk -v MM="Feb" 'BEGIN{
 x="Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06 Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12"
split(x,data)
for(i = 1 ; i < 25  ; i += 2)
{
mon[data[i]]=data[i+1]
}
{printf mon[MM]}
}'

This User Gave Thanks to vidyadhar85 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date conversion from 24 hr format to 12 hr format

hi i want to convert date procured from sone operation which will be in 24hr format to 12 hr format displaying AM and PM # date -d @1362545068 Tue Mar 5 23:44:28 EST 2013 # this Tue Mar 5 23:44:28 EST 2013 i want to convert it so that output is as below Tue... (2 Replies)
Discussion started by: vivek d r
2 Replies

2. Shell Programming and Scripting

Special format for numeric print out

Hi, I know this must be very simple and stupid question but I could not find a proper answer anywhere else, My script generates numeric values in the following format 3.01234567891E+03 I use %.11E in printf formatting, but I need to list my numbers as 0.30123456789E+04 basicly I... (14 Replies)
Discussion started by: hayreter
14 Replies

3. Shell Programming and Scripting

String variable to numeric conversion in perl

Hi guys I am having this strange issue.Well my requirement is like below Compare two values between flat file and oracle DB Via perl script I am easily getting the rowcount Now I connect sql plus via perl and the column value that returns is string my $sqlplus_settings = ''; my... (7 Replies)
Discussion started by: Pratik4891
7 Replies

4. Shell Programming and Scripting

Script to counting a specific word in a logfile on each day of this month, last month etc

Hello All, I am trying to come up with a shell script to count a specific word in a logfile on each day of this month, last month and the month before. I need to produce this report and email it to customer. Any ideas would be appreciated! (5 Replies)
Discussion started by: pnara2
5 Replies

5. Shell Programming and Scripting

Conversion of below Tabs Tex file into CSV format file : shell script needed

Request if some one could provide me shell script that converts the below "input file" to "CSV format file" given Name Domain Contact Phone Email Location ----------------------- ------------------------------------------------ ------- ----- ---------------------------------... (7 Replies)
Discussion started by: sreenath1037
7 Replies

6. Shell Programming and Scripting

Conversion of Exponential to numeric in awk- not correct output

Hi All, I have 1 million records file. Using awk, I am counting the number of records. But as the number is huge, after crossing a number, awk is displaying it in exponential format. At the end, I need to verify this count given by awk with expected count. But as it is in exponential format,... (3 Replies)
Discussion started by: ssunda6
3 Replies

7. Shell Programming and Scripting

changing month in Mmm format to mm FORMAT

i have an variable mydate=2008Nov07 i want o/p as in variable mymonth=11 (i.e nov comes on 11 number month) i want some command to do this for any month without using any loop. plz help me (1 Reply)
Discussion started by: RahulJoshi
1 Replies

8. Shell Programming and Scripting

:-) 1213: Character to numeric conversion error. Plz help

Dear friends, I am new to Unix/Linux. I am trying to run following query but getting an error msg... Please can u people help me in this? Query: echo "select status_ac from db_acct where acct_num=AAA000337" | dbaccess elstest Error: 217: Column (amd000337) not found in any table in the... (2 Replies)
Discussion started by: anushree.a
2 Replies

9. UNIX for Dummies Questions & Answers

Getting month and changing format

Hello, I would like to get todays moth and write it in this format: _06_ Any ideas? (7 Replies)
Discussion started by: marringi
7 Replies

10. UNIX for Dummies Questions & Answers

To convert the numeric month into alphabetic

hi , This function actually gives me the last month but as a numeric value what should i do to get it as suppose :Jul date '+%b %Y' | { read MONTH YEAR MONTH=`expr "$MONTH" - 1` echo $MONTH } Thanks. Rooh (2 Replies)
Discussion started by: rooh
2 Replies
Login or Register to Ask a Question