change field 2 date format


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users change field 2 date format
# 1  
Old 07-21-2010
change field 2 date format

from this input

WEBELSOLAR,29122009,1:1
WIPRO,15062010,2:3
ZANDUREALT,18012007,1:3

i want output as
WEBELSOLAR,20091229,1:1
WIPRO,20100615,2:3
ZANDUREALT,20070118,1:3

basically input is in ddmmyyyy format and i was to convert it to yyyymmdd format
# 2  
Old 07-21-2010
Code:
awk -F',' 'OFS="," {{$2=substr($2,5,4)substr($2,3,2)substr($2,1,2)} {print $1,$2,$3}}' data.file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help changing date format in the nth field

Hi, I have two (2) things that I want to do. First is to change the date format that is in the nth field from MM/DD/YY to YY/MM/DD. Preferably, I wish I know how to make it a 4-digit year but I don't. Problem is I can only assume it is a 20 century Second is somehow know how to figure out... (1 Reply)
Discussion started by: newbie_01
1 Replies

2. Shell Programming and Scripting

Change just the date format

need some more help please i have a large file and i want to change just the date format with awk or sed from this yyyy-mm-dd 2016-04-15 8.30 2016-04-15 7.30 2016-04-13 7.30 2016-04-11 8.30 2016-04-11 7.30 2016-04-08 8.30 2016-04-08 7.30 2016-04-06... (5 Replies)
Discussion started by: bob123
5 Replies

3. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

4. Shell Programming and Scripting

Change the date format

Hi, I was looking for a script to change the date from one format to other. A search in the forum gave me the below script as a result. #! /bin/ksh format=YYYYMMDD YEAR=${format%????} DAY=${format#??????} MON=${format#$YEAR} MON=${MON%$DAY} echo $MON/$DAY/$YEAR I got it... (2 Replies)
Discussion started by: prithvirao17
2 Replies

5. Shell Programming and Scripting

Date format change

Dear Friends, Need your help once again, I have a variable ( e.g. ${i}) whoch has date in MM/DD/YYYY (E.g. 12/31/2011) format. I want to change it to DD/MM/YYYY (e.g. 31/12/2011) format. Request you to guide me as we are unable to do the same. Thanks in advance Anu. (1 Reply)
Discussion started by: anushree.a
1 Replies

6. Shell Programming and Scripting

Change Date Format

Hi Guys, I had a scenario like this.. It seems very silly...dont think it as a home work question.....:) i tried it many ways but i didn't achieve this... start_date=May122011 here i want to change the start_date in to 20110512 start_date=20110512 tell me how can we achive... (5 Replies)
Discussion started by: apple2685
5 Replies

7. Shell Programming and Scripting

Change date format

Hi guys, I have a text file with lots of lines like this: MCOGT23R27815 27/07/07 27/05/09 SO733AM0235 30/11/07 30/11/10 NL123403N 04/03/08 04/03/11 0747AM7474 04/04/08 04/04/11 I want to change each line so the date format looks like this: MCOGT23R27815 07/07/27 09/05/27 ... (7 Replies)
Discussion started by: Tornado
7 Replies

8. Shell Programming and Scripting

Date Format Change

Hi I have a date format in a variable as Mon Jan 11 03:35:59 2010. how do i change it to YYYYMMDD format (3 Replies)
Discussion started by: keerthan
3 Replies

9. Shell Programming and Scripting

awk,cut fields by change field format

Hi Everyone, # cat 1.txt 1321631,77770132976455,19,20091001011859,20091001011907 1321631,77770132976455,19,20091001011859,20091001011907 1321631,77770132976455,19,20091001011859,20091001011907 # cat 1.txt | awk -F, '{OFS=",";print $1,$3,$4,$5}' 1321631,19,20091001011859,20091001011907... (7 Replies)
Discussion started by: jimmy_y
7 Replies

10. Solaris

change date format

dear members, ls -l drwxr-xr-x 40 root sys 1024 Jul 11 22:19 usr drwxr-xr-x 43 root sys 1024 Feb 1 2009 var i am using solaris 10 is that possibe to do drwxr-xr-x 40 root sys 1024 25-08-2009 22:19 usr drwxr-xr-x 43 root sys ... (4 Replies)
Discussion started by: hosney00ux
4 Replies
Login or Register to Ask a Question