How can I sort a CSV file by age in ascending order?

0
0
Asked By SunnySky123 On

I'm working with a CSV file that has names in column 'A' and ages in column 'B'. I want to sort this file by ages from low to high. I attempted to use the command `sort -t, -k2n "$workingFolder$inputFile"` but I'm getting a 'Not an integer' error, even though I thought ages were properly formatted as integers. Could it be that they're being treated as strings instead? Any advice would be really appreciated!

4 Answers

Answered By CodeWhisperer77 On

Just a heads up, `sort` does have limitations when it comes to CSV formats. It doesn't recognize escaped characters or quotes well, which can lead to errors. If it's a complex CSV, you might need a custom parser.

Answered By TechieSammy On

If you find the command line tricky, you could consider importing your CSV into a spreadsheet software like Excel or Google Sheets. They have built-in sorting options and are straightforward to use.

Answered By SortingNinja21 On

Instead of `-n`, you might want to try using `-g` for a bit more flexibility. It could help interpret your numbers better in some cases.

Answered By DataDude45 On

Sure! You can sort your CSV with a command like `sort -n -t ',' -k2 yourfile.csv`. Just make sure that your age column doesn't have any commas in the names; that might cause issues too. If that doesn't work, double-check if your ages are formatted correctly in the file.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.