[Solved] Need help changing a field from MM/DD/YY to DD/MM/YY format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Need help changing a field from MM/DD/YY to DD/MM/YY format
# 1  
Old 08-27-2012
[Solved] Need help changing a field from MM/DD/YY to DD/MM/YY format

Hi,
I need help changing a field from MM/DD/YY to DD/MM/YY format. Suppose a file a.csv. The record is

Code:
"11/16/09","ABC","        1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD"
"11/16/09","PQR","        2","EU","520892427","1","600","31351000","5467897","ANR BANK CO. LTD"

I need to change it to
Code:
"16/11/09","ABC","        1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD"
"16/11/09","PQR","        2","EU","520892427","1","600","31351000","5467897","ANR BANK CO. LTD"

Thanks,
Gangadhar
# 2  
Old 08-27-2012
Code:
$ cat infile
"11/16/09","ABC","        1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD"
"11/16/09","PQR","        2","EU","520892427","1","600","31351000","5467897","ANR BANK CO. LTD"
$ awk -F\" '{split($2,arr,"/"); $2=arr[2]"/"arr[1]"/"arr[3]; print}' OFS=\" infile
"16/11/09","ABC","        1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD"
"16/11/09","PQR","        2","EU","520892427","1","600","31351000","5467897","ANR BANK CO. LTD"

This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-27-2012
If all the records are like these, then:
Code:
$ cat file
"11/16/09","ABC","        1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD"
"11/16/09","PQR","        2","EU","520892427","1","600","31351000","5467897","ANR BANK CO. LTD"
$ sed 's|^"\([0-9]*\)/\([0-9]*\)/|"\2/\1/|' file
"16/11/09","ABC","        1","EU","520892414","1","600","31351000","1234567","ANR BANK CO. LTD"
"16/11/09","PQR","        2","EU","520892427","1","600","31351000","5467897","ANR BANK CO. LTD"

--
Bye
# 4  
Old 08-27-2012
Thank you dear .. It worked Smilie
# 5  
Old 08-27-2012
Code:
sed 's:.\(.*/\)\(.*/\):"\2\1:' infile

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. Solaris

[Solved] Question changing timezone rules / zic

Dear, One of our customer which is located in Iraq/Baghdad, has informed us about a official change in daylight saving time in few days later and has asked us to fix this issue. So, the current timezone of that system is set as 'Asia/Baghdad' which is correct. however to fix the issue I went... (0 Replies)
Discussion started by: Anti_Evil
0 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

Changing field X in file

/etc/newsyslog.conf on a Mac OSX system contains: # configuration file for newsyslog # $FreeBSD: /repoman/r/ncvs/src/etc/newsyslog.conf,v 1.50 2005/03/02 00:40:55 brooks Exp $ # # Entries which do not specify the '/pid_file' field will cause the # syslogd process to be signalled when that... (3 Replies)
Discussion started by: jnojr
3 Replies

5. Shell Programming and Scripting

[Solved] Changing 0 to 1 and 1 to 0

Hi I have an expression that returns 1 if a text is found and 0 if its not found. I need it the other way around. 0 of found and 1 if its not found echo $((`cat /var/log/system1/output.html | grep aligment | head -n1 | wc -l`)) Is this possible without doing an if/then/else, just... (5 Replies)
Discussion started by: Jotne
5 Replies

6. Shell Programming and Scripting

[SOLVED] Changing file names

I have written a csh script that changes the name of file from src to dst. I am getting the error below: TESTAmvfiles DONE TESTAmvfiles set: Variable name must begin with a letter. The csh script is: #!/bin/csh #... (0 Replies)
Discussion started by: kristinu
0 Replies

7. Shell Programming and Scripting

[Solved] Changing to upper case in csh

How can I change a string contained in a variable to upper case using csh ??? ---------- Post updated at 08:39 AM ---------- Previous update was at 08:29 AM ---------- I think I've got it, using tr has solved the problem set opt = ` echo $opt | tr "" "" ` (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

how I can add a constant to a field without changing the file format

Hi, I need to edit a file Protein Data Bank (pdb) and then open that file with the program VMD but when I edit the file with awk, it changes pdb format and the VMD program can not read it. I need to subtract 34 to field 6 ($ 6). this is a pdb file : ATOM 918 N GLY B 103 -11.855 8.675... (8 Replies)
Discussion started by: bio_
8 Replies

9. UNIX for Dummies Questions & Answers

Changing from Excel date format to MySQL date format

I have a list of dates in the following format: mm/dd/yyyy and want to change these to the MySQL standard format: yyyy-mm-dd. The dates in the original file may or may not be zero padded, so April is sometimes "04" and other times simply "4". This is what I use to change the format: sed -i '' -e... (2 Replies)
Discussion started by: figaro
2 Replies

10. 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
Login or Register to Ask a Question