Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vim: A question about sorting by column

2,442 views
Skip to first unread message

James Egan

unread,
Jun 29, 2008, 10:37:20 PM6/29/08
to
Is it possible in vim to sort the data below, similar to using the
external sort to sort on say the 8th column like:

cat data.txt | sort -k 8n


10 FTP 000105606 59204 00000200733301006A1 N NAME F
11 FTP 000105606 59204 00000200733301002A1 N NAME F
12 FTP 000105606 59204 00000200733301004A1 N NAME 6
13 FTP 000105606 59204 00000200733201002A1 N NAME F
14 FTP 000105606 59204 00000200733301000A1 N NAME F
9 FTP 000105606 59204 00000200733401001A1 N NAME F
8 FTP 000105607 59205 00000200805101028A1 N NAME 9
3 FTP 232190010 00121 00000200812701437A1 N NAME 9
1 FTP 294243080 16976 00000200812804587A1 N NAME F
3 FTP 432817773 17014 00000200812705212A1 N NAME 7
3 FTP 538105321 00007 00000200812801004A1 N NAME 7


-Thanks

Patrick Texier

unread,
Jun 30, 2008, 4:22:39 AM6/30/08
to
Le Sun, 29 Jun 2008 22:37:20 -0400, James Egan a écrit :

> Is it possible in vim to sort the data below, similar to using the
> external sort to sort on say the 8th column like:
>
> cat data.txt | sort -k 8n

:sort /.*\%8v/

:help :sort
--
Patrick Texier

vim:syntax=mail:ai:ts=4:et:tw=72

Bob Harris

unread,
Jun 30, 2008, 9:32:51 PM6/30/08
to
In article <RoCdnRpUgZx92_XV...@comcast.com>,
James Egan <jega...@comcast.net> wrote:

Or select the lines you wish to sort using the Capital V command.
Then enter

!sort -k 8n

J O'Connell

unread,
Jul 2, 2008, 7:01:55 PM7/2/08
to
Patrick Texier wrote:
> Le Sun, 29 Jun 2008 22:37:20 -0400, James Egan a écrit :
>
>> Is it possible in vim to sort the data below, similar to using the
>> external sort to sort on say the 8th column like:
>>
>> cat data.txt | sort -k 8n
>
> :sort /.*\%8v/
>
> :help :sort

I believe the example the OP cites is better solved as

:sort /.*\%55v/

The 'virtual' specification is the absolute column number, which treats
spaces and tabs as a single character (in other words, it does NOT count
tabs as 8 spaces (or whatever your tab settings are).

In the case cited by the OP, working with the assumption that all
whitespaces are space characters, the eighth column starts at character
number 55.

-Fionn

0 new messages