Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Date format from Jan 01 2015 11:00:00 PM to 01/01/2015 23.00.00 Post 302943660 by Don Cragun on Monday 11th of May 2015 03:45:19 PM
Old 05-11-2015
The following script seems to work with the two file formats you gave as samples. This was tested using the Korn shell, but it should work with any shell that recognizes basic Bourne shell syntax:
Code:
#!/bin/ksh
awk '
BEGIN {	mon["Jan"] = "01";	mon["Feb"] = "02";	mon["Mar"] = "03"
	mon["Apr"] = "04";	mon["May"] = "05";	mon["Jun"] = "06"
	mon["Jul"] = "07";	mon["Aug"] = "08";	mon["Sep"] = "09"
	mon["Oct"] = 10; 	mon["Nov"] = 11;	mon["Dec"] = 12
	FS = OFS = "|"
}
function dc(fn,		d, h, n) {
	n = split(" " $fn, d, /[ :]+/)
	h = (d[5] == 12 ? 0 : d[5]) + (d[8] == "AM" ? 0 : 12)
	$fn = sprintf("%s/%s/%s %02d.%s.%s", mon[d[2]], d[3], d[4], h, d[6], d[7])
}
NF == 7 {
	dc(3)
}
{	dc(NF)
}
1' "$1"

Save the above code in a file (I used tester) for this example and make it executable:
Code:
chmod +x tester

I strongly encourage you not to include spaces and quotes in your filenames. But, with the sample files you specified, the following commands seem to convert your files as requested:
Code:
./tester 'File1 '

produces the output:
Code:
Richard|Standard | Not asigned| Insured | New York |01/01/2015 23.00.00
John | Not Standard |  asigned| Insured | New York |01/01/2015 23.00.00
James | No| Assigned| No| New york |01/01/2015 23.00.00

And, the command:
Code:
./tester 'File 2"'

produces the output:
Code:
Richard|Standard |11/01/2014 22.00.00| Not asigned| Insured | New York |01/01/2015 23.00.00
John | Not Standard |01/05/2014 23.00.00|  asigned| Insured | New York |01/01/2015 23.00.00
James | No|09/01/2014 10.00.00| Assigned| No| New york |01/01/2015 23.00.00

 

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl one-liner to get yesterday's date in format dd-MMM-yy (i.e. 01-JAN-12)

I have the following perl one-liner to get yesterday's date, but I would like it in the form of dd-MMM-yy (for example: 01-JAN-12). Can someone alter the below code so I get the format I want? Also, could someone also give me a line for dd-Mmm-yy (for example 01-Jan-12)? Code: YEST=`perl -w... (3 Replies)
Discussion started by: thibodc
3 Replies

2. Shell Programming and Scripting

How to convert date format such as 7/18/2015 to the number of month

How to convert date format such as 7/18/2015 to the number of month from requesting date 'date' in sh scripting ? Let say I have output in my log.txt -> 7/18/2015. How I convert it to the full number of month starting from 'date' till 7/18/2015 in shell scripting ? Thanks in advance. (1 Reply)
Discussion started by: amerabest
1 Replies

3. What is on Your Mind?

While Happy; do @ ;done < 2015

http://i62.tinypic.com/zt6a08.jpg (2 Replies)
Discussion started by: ongoto
2 Replies

4. Solaris

Leap second for year 2015

I hear the Leap second for 2015 will occur on June 30 at 23:59:60 according to the wild rumours from internet the expected impact ranges from crashing to hanging servers. Can anybody share their preparations what they have done for solaris servers? are there any patches to install or workaround?... (1 Reply)
Discussion started by: sparcguy
1 Replies

5. What is on Your Mind?

LinuxCon Seattle 2015

Only a little over a week until I head out to LinuxCon in Seattle. Anyone else attending this year? (0 Replies)
Discussion started by: Gallavin
0 Replies

6. SCO

Strange behaviour on Openserver 5.0.2 after 09/2015

Dear friends, i am having some Problems with a Sco Openserver in a Box (normally on VMWare, importing it on a Virtualbox does the same). When i boot up the system on xx/09/2015 i got fork failed - too many processes during startup. The programs which should run on the server, do not run. I... (67 Replies)
Discussion started by: ChipperEs
67 Replies
Locale::Codes::LangExt(3)				User Contributed Perl Documentation				 Locale::Codes::LangExt(3)

NAME
Locale::Codes::LangExt - standard codes for language extension identification SYNOPSIS
use Locale::Codes::LangExt; $lext = code2langext('acm'); # $lext gets 'Mesopotamian Arabic' $code = langext2code('Mesopotamian Arabic'); # $code gets 'acm' @codes = all_langext_codes(); @names = all_langext_names(); DESCRIPTION
The "Locale::Codes::LangExt" module provides access to standard codes used for identifying language extensions, such as those as defined in the IANA language registry. Most of the routines take an optional additional argument which specifies the code set to use. If not specified, the default IANA language registry codes will be used. SUPPORTED CODE SETS
There are several different code sets you can use for identifying language extensions. A code set may be specified using either a name, or a constant that is automatically exported by this module. For example, the two are equivalent: $lext = code2langext('acm','alpha'); $lext = code2langext('acm',LOCALE_LANGEXT_ALPHA); The codesets currently supported are: alpha This is the set of three-letter (lowercase) codes from the IANA language registry, such as 'acm' for Mesopotamian Arabic. This is the default code set. ROUTINES
code2langext ( CODE [,CODESET] ) langext2code ( NAME [,CODESET] ) langext_code2code ( CODE ,CODESET ,CODESET2 ) all_langext_codes ( [CODESET] ) all_langext_names ( [CODESET] ) Locale::Codes::LangExt::rename_langext ( CODE ,NEW_NAME [,CODESET] ) Locale::Codes::LangExt::add_langext ( CODE ,NAME [,CODESET] ) Locale::Codes::LangExt::delete_langext ( CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_alias ( NAME ,NEW_NAME ) Locale::Codes::LangExt::delete_langext_alias ( NAME ) Locale::Codes::LangExt::rename_langext_code ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::add_langext_code_alias ( CODE ,NEW_CODE [,CODESET] ) Locale::Codes::LangExt::delete_langext_code_alias ( CODE [,CODESET] ) These routines are all documented in the Locale::Codes::API man page. SEE ALSO
Locale::Codes The Locale-Codes distribution. Locale::Codes::API The list of functions supported by this module. http://www.iana.org/assignments/language-subtag-registry The IANA language subtag registry. AUTHOR
See Locale::Codes for full author history. Currently maintained by Sullivan Beck (sbeck@cpan.org). COPYRIGHT
Copyright (c) 2011-2013 Sullivan Beck This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.16.3 2013-02-27 Locale::Codes::LangExt(3)
All times are GMT -4. The time now is 06:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy