How do I remove first 5 characters in each line in a text file using vi?

How do I remove the first 5 characters in each line in a text file?
I have a file like this:

   4 Alabama
   4 Alaska
   4 Arizona
   4 Arkansas
   4 California
  54 Can
   8 Carolina
   4 Colorado
   4 Connecticut
   8 Dakota
   4 Delaware
  97 Do
   4 Florida
   4 Hampshire
  47 Have
   4 Hawaii

I'd like to remove the number and the space at the beginning of each line in my txt file.


Solution 1:

:%s/^.\{0,5\}// should do the trick. It also handles cases where there are less than 5 characters.

Solution 2:

Use the regular expression ^..... to match the first 5 characters of each line. use it in a global substitution:

:%s/^.....//

Solution 3:

As all lines are lined up, you don't need a substitution to solve this problem. Just bring the cursor to the top left position (gg), then: CTRL+vGwlx

Solution 4:

Since the text looks like it's columnar data, awk would usually be helpful. I'd use V to select the lines, then hit :! and use awk:

:'<,'>! awk '{ print $2 }'

to print out the second column of the data. Saves you from counting spaces altogether.