How to sort file rows with vi?

By : Stephan

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


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?

By : Stephan

  1. Hi light the rows you want to sort with "V" command

  2. Use a bash command with "!" to work on the selection, like:

    !sort -k 10

Where the number is the column number where your second (sort) column starts.

vi will replace the selection with the output of the sort command - which is given the original selection.

By : Brad

delimit the column using some char here I have | symbol as delimiter, once did with that you can use below command to sort specific column use -n if u want to sort numeric and its working on some version of vi and not on ubuntu vi :(

/|.*|/ | sort

By : vicky

This video can help you solving your question :)
By: admin