Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort file lines in Bash

Tags:

file

linux

bash

How can sort lines in a file according to data in it? Say I have a file who looks like this:

1 23 54 89
2 65 23 77
9 89 67 90
8 78 93 11
3 74 99 32

And I want to sort it according to the first column like this:

1 23 54 89
2 65 23 77
3 74 99 32
8 78 93 11
9 89 67 90

It all has to be done in Bash.

like image 361
user3206874 Avatar asked Dec 02 '25 06:12

user3206874


2 Answers

sort is your go to.

sort <your_file>
like image 83
Sravan K Ghantasala Avatar answered Dec 03 '25 19:12

Sravan K Ghantasala


Try using the sort command:

sort -n test.txt
like image 39
SMA Avatar answered Dec 03 '25 19:12

SMA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!