Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

How to sort a file by n-column

Answer:

Suppose you have a CSV file:

1,c
2,d
3,a

How do you sort by the 2nd column?

Here is the command you need:

# sort -k2 input.txt -t ','

where -t ',' mean the comma separator, and -k2 mean the 2nd column.

  1. Extract column data using awk
  2. Sort numerical value using the sort command
  3. How to sort IP addresses in Linux
  4. Print a particular column data using awk
  5. Convert a Nero .nrg file to .iso file

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>