Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

Bash - how to sort lines?

0 contributions
7 points

Sort operation can be achieved with sort command.

1. Sorting by rows:

$ sort path/to/textual/file

2. Reversed sorting by rows:

sort -r path/to/textual/file

3. Number sorting:

sort –n path/to/textual/file

4. Sorted by first column (pipe used):

cat /etc/passwd | cut -d : -f 1 | sort

Note: delimiter set as colon.

5. Sorted by third and fourth columns (pipe used):

cat path/to/textual/file | sort -k 3 -k 4 -n

Note: default delimiters are space and tab.

6. Linux user list sorted by id:

cat /etc/passwd | cut -d : -f 1,3 | sort -t ':' -k 2 -n

Note: delimiter set as colon; selected columns are 1st and 3rd; sorting by id.

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more