I am in need of reorganizing a large CSV file. The first column, which is currently a 6 digit number needs to be split up, using commas as the field separator.
For example, I need this:
022250,10:50 AM,274,22,50
022255,11:55 AM,275,22,55
turned into this:
0,2,2,2,5,0,10:50 AM,274,22,50
0,2,2,2,5,5,11:55 AM,275,22,55
Let me know what you think!
Thanks!
It’s a lot shorter in perl:
Since you don’t know perl, a quick explanation.
-F,indicates the input field separator is the comma (like awk).-aactivates auto-split (into the array@F),-nimplicitly wraps the code in awhile (<>) { ... }loop, which reads input line-by-line.-eindicates the next argument is the script to run.$,is the output field separator (it gets set iteration of the loop this way, but oh well).splithas obvious purpose, and you can see how the array is indexed/sliced.print, when lists as arguments like this, uses the output field separator and prints all their fields.In awk: