I need to sort and diff a few lists that have 1,000s of entries on them. The lists looks like:
11-2-3049_2007_squib.pdf
11-11-5476_2004_squib.pdf
13-2-5477_2006_squib.pdf
14-3-3045A_2004_squib.pdf
14-CMF-3046_2004_squib.pdf
14-2-3047_2005_squib.pdf
14-4-3048_2004_squib.pdf
15-7-3050P_2004_squib.pdf
I'm looking to sort by the number between the second -
and before the _
, such as 3049
in the first example.
I've not been able to combine the sort by column and regex stuff with any success. What do you all suggest?
This should do the trick:
:sort r /\v^(.{-}-){2}\zs.{-}\ze_/
See
:help sort
for background here
The regex contains a few twists and turns:
\v
to engage very magic mode (reducing the need for escaping)\zs
and \ze
to mark the begin and end of the actual match result{-}
to perform non-greedy kleene-star match (in Perl notation, .{-}
would be .*?
)Use the external sort
program:
:%!sort -n -t- -k3,3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With