简体   繁体   中英

How do I remove the first string on every line in vim?

I have a text file that's thousands of lines long. Every line starts with a string of 8 hex numbers. I need to remove this string on every line. How do I do this in vim?

用空字符串替换任何行上的前8个十六进制字符(0-9位数字,af / AF字母):

 :%s/^[0-9a-fA-F]\{8\}//gc

Use ^V for block select, highlight your eight columns, and delete as normal.

Or use :s :

:%s/\v^[a-fA-F0-9]{8}//

If the line is

12345678 Something else

a total of 9 chars is to be removed from the head of each line, in VIM

:1,$s/^.........//

should do the trick (9 dots),

  • : to tell vim you want to enter a command
  • 1,$ means the command affects from line 1 to the last (or g global)
  • s means substitute
  • ^ means beginning of line
  • ..... means 5 (any) chars
  • s/^.....// means replace 5 chars at start of line with nothing

edit to match the number of hex chars from the question..

use cut command. This way is much more straight forward.

echo '12345678 Something else' | cut -c 10-

result:

Something else

Just remind, cut index string start from 1 instead of 0.

In vi , we could just run cut in vi :

:%!cut -c 10-

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM