Reputation: 89
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?
Upvotes: 1
Views: 2160
Reputation: 1725
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-
Upvotes: 1
Reputation: 28830
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 command1,$
means the command affects from line 1 to the last (or g
global)s
means substitute^
means beginning of line.....
means 5 (any) charss/^.....//
means replace 5 chars at start of line with nothingedit to match the number of hex chars from the question..
Upvotes: 1
Reputation: 48536
Use ^V for block select, highlight your eight columns, and delete as normal.
Or use :s
:
:%s/\v^[a-fA-F0-9]{8}//
Upvotes: 1
Reputation: 19194
Replace first 8 hex chars (0-9 digits, a-f/A-F letters) on any line with empty string:
:%s/^[0-9a-fA-F]\{8\}//gc
Upvotes: 1