Search code examples
vimvineovim

Keep just the last 10 characters of a line


I have a file which is as following

!J INCé0001438823
#1 A LIFESAFER HOLDINGS, INC.é0001509607
#1 ARIZONA DISCOUNT PROPERTIES LLCé0001457512
#1 PAINTBALL CORPé0001433777
$ LLCé0001427189
$AVY, INC.é0001655250
& S MEDIA GROUP LLCé0001447162

I just want to keep the last 10 characters of each line so that it becomes as following:-

0001438823
0001509607
0001457512
0001433777
0001427189
0001655250

Solution

  • :%s/.*\(.\{10\}\)/\1
    :                     ex-commaned
     %                    entire file
      s/                  substitute
        .*                anything (greedy)
            .             followed by any character
             \{10\}       exactly 10 of them
          \(       \)     put them in a match group
                     /    replace with
                      \1  said match group