I need to write a script which will be operating on the CSV files, containing for example 4 columns. The CSV file will have to be sorted twice, first by the first column and then by the third column. As to sort lines with separator is quite easy I need an advice of what is the best way to do this two-step sorting? I think it will be a little bit hard to do these sorting sequentially, and the smartest way will be sorting the 3rd column on the prepared section of lines with the same values from sorted first column, then on the section with the same next values, etc… and at the end merge everything…
Example of the CSV:
AB08,ANYTHING,EXAMPLE_2,ANYTHING
AB24,ANYTHING,EXAMPLE_2,ANYTHING
AB08,ANYTHING,EXAMPLE_1,ANYTHING
AB06,ANYTHING,EXAMPLE_1,ANYTHING
AB24,ANYTHING,EXAMPLE_1,ANYTHING
AB08,ANYTHING,EXAMPLE_3,ANYTHING
Desired look:
AB06,ANYTHING,EXAMPLE_1,ANYTHING
AB08,ANYTHING,EXAMPLE_1,ANYTHING
AB08,ANYTHING,EXAMPLE_2,ANYTHING
AB08,ANYTHING,EXAMPLE_3,ANYTHING
AB24,ANYTHING,EXAMPLE_1,ANYTHING
AB24,ANYTHING,EXAMPLE_2,ANYTHING
I would use PHP script to sort and parse it but I wonder if shell commands won’t be better to handle this issue (sort/grep/awk)?
Thanks for any help 🙂
Cheers
should do the trick.