I have the following script which converts some data in a CSV file from one format to another. However, I have to convert the CSV (Macintosh) file to CSV or CSV (MS-DOS) first else the script wont work. I do this in Excel. I know it has something to do with the line endings, where CSV (Macintosh) saves with CR as the new-line character, and CSV (Comma delimited) and CSV (DOS) both use CR/LF.
Is there a way to add something to the top of my script that negates the need for me to convert manually?
The example you showed doesn't have any dates in it.
Show representative input and representative output and we can try. Otherwise we'll blindly do things which do what you say, not what you actually want.
The data has many columns so the script above searches for any columns with format xxx/xxx and then converts according to the calculations. It also avoids column 2.
It looks like that if I first replace "/" with "," with the tr utility, and then run the script, it works. However, its of course also splitting the date. So, I need to incorporate something into the script so that it replaces the delimiter first, avoids the date column and then runs the calculations on xxx/xxx.
So it's basically CSV already, but the last column is a problem. OK. You can tell awk "substitute / for , in the very last column". You can also tell it 'print \r\n at the end of lines' so you don't need unix2dos after:
Thanks Corona. But as I said, there's many columns (way too many to paste here) and several of them have the format xxx/xxx, not just the last column. It just needs to ignore column 2 and change the delimiter everywhere else.