Answer the question
In order to leave comments, you need to log in
bash. How to sort csv file in bash?
Good time.
There is a file.csv file like this:
"FIELD_1, 2", 2
"FIELD_1",1
"FIELD_1, 2, 3", 3
If you run
sort --field-separator="," -k2 -n file.csv > sorted .csv
In theory, sorted.csv should contain sorted data by the 2nd field, but this does not work because the quotes contain commas. How can this be resolved.
As a result, I want to get the file
"FIELD_1",1
"FIELD_1, 2", 2
"FIELD_1, 2, 3", 3
Thanks in advance
Answer the question
In order to leave comments, you need to log in
so simple and sort by the second field:sort -k2 -n file.csv > sorted.csv
Yes, everything seems to work - I tried it (I'm learning myself), I didn't even write the code, your copy / paste-silt.
what is contained in quotes "" is read as a single string/character. -FALSE is
the only thing / maybe the csv itself needs to be split into lines beforehand,
or does each FILD value / parameter start on a new line?
then it should work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question