Date format change in UNIX .dat file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Date format change in UNIX .dat file
# 1  
Old 06-09-2014
HP Date format change in UNIX .dat file

Hi,

I need help to convert the date format in .DAT file in unix.
I want to convert
Code:
10@@|SWIFT MT568 Extract@@|Apr 14 2014  5:47:52:563PM@@|Apr 14 2014  4:33:47:663PM@@||##|

into

Code:
10@@|SWIFT MT568 Extract@@|04/14/2014/  5:47:52:563PM@@|04/14/2014  4:33:47:663PM@@||##|

Appreciate your help int hsi regard.

Moderator's Comments:
Mod Comment edit by bakunin: please, instead of using some myriad of markup simply wrap CODE-tags around your sample. Its easier and at the same time easier to read too. Thank you.

Last edited by bakunin; 06-09-2014 at 05:07 AM..
# 2  
Old 06-09-2014
Welcome to forums,

if you have gawk try

Code:
$ cat file
10@@|SWIFT MT568 Extract@@|Apr 14 2014 5:47:52:563PM@@|Apr 14 2014 4:33:47:663PM@@||##|

Code:
awk --re-interval 'BEGIN{
			  mon="JanFebMarAprMayJunJulAugSepOctNovDec"
			}
			{
			  if(match($0,/[[:alpha:]]{3}[[:space:]][[:digit:]]{2}[[:space:]][[:digit:]]{4}/,m))
			  {
			     split(m[0],A)
			     gsub(m[0],sprintf("%02d/%02d/%04d",(match(mon,A[1])+2)/3,A[2],A[3]) )
			  }
		        }1
                   ' file

Code:
10@@|SWIFT MT568 Extract@@|04/14/2014 5:47:52:563PM@@|04/14/2014 4:33:47:663PM@@||##|

This User Gave Thanks to Akshay Hegde For This Post:
# 3  
Old 06-09-2014
Getting error

Hi, Thanks for your code. When I am executing your code I am getting the below error. I do not know why? Coudl you please help...I appreciate your help in this regard. I am not a expert in UNIX shell. Smilie

Code:
awk: syntax error near line 5
awk: illegal statement near line 5
awk: bailing out near line 5


Last edited by Scrutinizer; 06-09-2014 at 07:30 AM.. Reason: code tags
# 4  
Old 06-09-2014
May be you are on solaris/sunos, try this

Code:
nawk 'BEGIN{
	    mon="JanFebMarAprMayJunJulAugSepOctNovDec"
	   }
	  {
	   if(match($0,/...[[:space:]]..[[:space:]]..../))
	   {
	     m = substr($0,RSTART,RLENGTH); split(m,A)
	     gsub(m,sprintf("%02d/%02d/%04d",(match(mon,A[1])+2)/3,A[2],A[3]) )
	   }
          }1
     ' file

---------- Post updated at 03:32 PM ---------- Previous update was at 03:30 PM ----------

Please Note : I assumed that date will be same and time is changing in your file
This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 06-09-2014
Error

Thanks for your quick reply. Yes. I am using Solaris 5.10. While I am using your code, the screen stays idle and does not look processing....When I change nawk ino awk then I am gettign below error.
Code:
awk: syntax error near line 6
awk: illegal statement near line 6
awk: syntax error near line 9
awk: illegal statement near line 9
awk: syntax error near line 12
awk: bailing out near line 12

--Thanks

Last edited by Scrutinizer; 06-09-2014 at 07:30 AM.. Reason: code tags
# 6  
Old 06-09-2014
Quote:
Originally Posted by karthikengox
Thanks for your quick reply. Yes. I am using Solaris 5.10. While I am using your code, the screen stays idle and does not look processing....When I change nawk ino awk then I am gettign below error.
awk: syntax error near line 6
awk: illegal statement near line 6
awk: syntax error near line 9
awk: illegal statement near line 9
awk: syntax error near line 12
awk: bailing out near line 12
--Thanks
Change awk to nawk

As Don says always,

If you want to try this on a Solaris/SunOS system, change awk at the start of this script to /usr/xpg4/bin/awk ,/usr/xpg6/bin/awk , or nawk
This User Gave Thanks to Akshay Hegde For This Post:
# 7  
Old 06-09-2014
Screen idle

Thanks for your reply again. I changed as per your instruction. /usr/xpg4/bin/awk. But the screen is idle and nothing seems to be running. Cursor stays in next line and no execution at all.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Change date format in a file.

Hi all, I have a file as below, i would like the change the format of the time from "11/7/2019 20:12" to "2019-07-11 20:12:00" in the last coloumn. any awk solution on this. Input: 2,0,695016,1961612,497212,5800804,0,0,161,33,7605,12226,23,10,66,0,0,34,11/7/2019 20:10... (4 Replies)
Discussion started by: Raghuram717
4 Replies

2. Shell Programming and Scripting

Change date format in am/pm in csv files using UNIX

Hi All, I'm new to forum good to hear all. I stuck in converting date format in csv file using unix csv file contains as below ,750,0000000000000000GCJR, ,06/22/2016 14:48:44 I want to convert into as below ,750,0000000000000000GCJR, ,06/22/2016 02:48:44 PM Please reply asap..... (22 Replies)
Discussion started by: Raghureds
22 Replies

3. Shell Programming and Scripting

Date format change in a csv file

Hi, We have csv file where date is coming in MM/DD/YYYY HH:MM:SS (06/23/2015 20:59:12) in multiple places But we need to change the date format to DD/Mon/YYYY HH:MM:SS (23/Jul/2015 20:59:12) using shell script. Please let us know how can we achieve the same. (16 Replies)
Discussion started by: dholea
16 Replies

4. Shell Programming and Scripting

Need to change date format in a csv file using awk

Example: Input csv file 00245DLS,Sitel Ocala,12/31/2014,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel Ocala,12/31/2014,19:00,-1.00,-1.00,-1.00,-1.00 00245HB,Charlotte,01/01/2015,00:00,-1.00,-1.00,-1.00,0.00 Output csv file 00245DLS,Sitel Ocala,2014/12/31,18:45,1.00,7.00,0.00,0.00 00245DLS,Sitel... (8 Replies)
Discussion started by: adit
8 Replies

5. Shell Programming and Scripting

Change the date and time format in UNIX script.

Hi, I am extracting a date string from the source file like this : 06/05/2014 16:04:00 I want to change it to 05-JUN-14 04.05.00.000000000 PM I basically store the date in a variable. I got solutions to change date in dd-mmm-yyyy format using tr but I guess it works only with the "date"... (8 Replies)
Discussion started by: Varshha
8 Replies

6. Shell Programming and Scripting

How to change the format of the date column in a flat file?

Hi, i have a flat file namely temp.txt with this data below ID|name|contact_date 101|Kay|2013-12-26 102|let|2013-12-26 I need to modify the date data in the flat file into MM/DD/YYYY HH24:MI:SS format let me know the code for this. Thank you! (5 Replies)
Discussion started by: srikanth_sagi
5 Replies

7. UNIX for Dummies Questions & Answers

Rename all Files in a UNIX Directory from one date format to another date format

Hi Unix Gurus, I would like to rename several files in a Unix Directory . The filenames can have more than 1 underscore ( _ ) and the last underscore is always followed by a date in the format mmddyyyy. The Extension of the files can be .txt or .pdf or .xls etc and is case insensitive ie... (1 Reply)
Discussion started by: pchegoor
1 Replies

8. Shell Programming and Scripting

File date format how to change

Hi All, Below are the unix files taken by the help of ls -lrt -rw-r--r-- 1 kbehera Domain Users 293 Jul 27 13:33 sand.txt -rw-r--r-- 1 kbehera Domain Users 4 Jul 27 13:37 sand1.txt -rw-r--r-- 1 kbehera Domain Users 293 Jul 27 15:30 new_sand.txt -rw-r--r-- 1 kbehera Domain Users 0 Jul 27... (2 Replies)
Discussion started by: krupasindhu18
2 Replies

9. Shell Programming and Scripting

How to change date format in file

Hello! I have a textfile that look like this: "83d1:46:2b";"20091008190000";"Rögle BK - Skellefteå";"Swedish" "d4c:46:21";"20091008190000";"Södertälje - Brynäs";"Swedish" "d4b:46:2";"20091008190000";"HV 71 - Färjestad";"Swedish" "838:46:b";"20091010160000";"Skellefteå - HV 71";"Swedish"... (2 Replies)
Discussion started by: condmaster
2 Replies

10. Shell Programming and Scripting

script to change the date format in a file

i have many files with date format of 6-9-2008 and i want a script that can change the format to 2008-06-09 Thanks (15 Replies)
Discussion started by: shehzad_m
15 Replies
Login or Register to Ask a Question