Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort file rows with vi?

I have to edit multiple files with multiple rows, and also everything is in three columns, like this:

#file

save    get    go
go      save   get
rest    place  reset

Columns are separated with tab. Is there any possible way to sort rows based on second or third column using vi?

like image 371
Stephan Avatar asked Oct 19 '25 04:10

Stephan


2 Answers

sort by the 2nd col:

:sor /\t/ 

sort by the 3rd col:

:sor /\t[^\t]*\t/   
like image 175
Kent Avatar answered Oct 22 '25 03:10

Kent


Second column:

:sort /\%9c/

Third column:

:sort /\%16c/

\%16c means "column 16".

like image 24
romainl Avatar answered Oct 22 '25 05:10

romainl



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!