I want to sort on a certain column only for rows containing a certain word. I don\'t want to see rows not containing that word. For example I have this text file:
Maxim Kim has already given an excellent answer and I was going to add this in a comment, but it just got too complicated so I'll stick it in an answer:
You could simplify the pattern by using:
:v/sdf/d
sort n /\D*/
as \D
is equivalent to [^[:digit:]]
and is a lot less typing. For more information, see
:help \D
To match on the third field specifically, rather than just the first digit, use
:sort n /\(\S\+\s+\)\{2}/`
or
:sort n /\v(\S+\s+){2}/
See:
:help :sort
:help \S
:help \s
:help pattern.txt
:help \v
As an aside, some find it easier to remember :g!/sdf/d
, which does the same as :v/sdf/d
- :g!
is the opposite of :g
and is identical to :v
.
:help :v
:help :g