0

I am trying to convert SQL file to CSV format and using unix/linux command to do so.

I am stuck at a place where I have to transform few colomns from 02-09-2013 or 02/09/2013 to 09-FEB-2013.

SQL File looks like:

INSERT INTO PRODMETH(ITEM, LOC, PRODUCTIONMETHOD, DESCR, EFF, PRIORITY, MINQTY, INCQTY,
DISC, LEADTIME, MAXQTY, OFFSETTYPE)
VALUES ('ABCD','PLANT','RT_ABCD_PLANT','Sort2B',TO_DATE('01/01/1970 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'),'1','0','0',
TO_DATE('01/01/1970 12:00:00 AM','MM/DD/YYYY HH:MI:SS AM'),'0','0','1');

I am looking for a bash command which would read file and change all occurrence of mm/dd/yyyy to dd-MON-yyyy.

jarlh
  • 42,561
  • 8
  • 45
  • 63
shivi
  • 1
  • 2
    Which dbms are you using? – jarlh Jan 08 '20 at 09:33
  • not sure to understand, do you want to change the sql command(s) using bash? – Corentin Limier Jan 08 '20 at 09:48
  • I want to change the whole file to CSV like below: 31-AUG-2013,31-AUG-13,29-AUG-13,29-AUG-13,201308,2013 AUG,201303,2013 Q3,2013,2013,ALL 02-SEPT-2013,02-SEP-13,01-SEP-13,01-SEP-13,201309,2013 SEP,201303,2013 Q3,2013,2013,ALL 03-FEB-2013,03-SEP-13,01-SEP-13,01-SEP-13,201309,2013 SEP,201303,2013 Q3,2013,2013,ALL – shivi Jan 08 '20 at 10:08
  • basically looking to change time stamp format to date format in all the files using unix command, which would read 1000 files and replace the said values with correct date format – shivi Jan 08 '20 at 10:10
  • You have referred to a table as a file. Then you want to run bash on it. I voted to close as unclear what you are asking because I really don't follow what you want to do. You might want to ask a question with just the "bash" tag and examples of the CSV files that you are dealing with. – Gordon Linoff Jan 08 '20 at 12:17

1 Answers1

0

Not sure about the bash command to do this, but you could use FORMAT_DATE(date, '%Y-%b-%d') in SQL which would result in formatting your date as you need.

Hope this helps

  • what is the command for it? There are over 2000 SQL files for which I need conversion to csv and change date format – shivi Jan 08 '20 at 09:51