regexunixtextcommandvi

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

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