+1  A: 

The easiest way would probably be using a macro. Press qa to start a recording in register a. Then remove the characters the way you're used to in Vim. Press q to stop recording. Then, take the amount of lines and append @a, for example for 4, press 4@a. This will repeat the macro 4 times.

Arda Xi
+13  A: 

Run the command: :%s/.* - //

Edit, explanation:

%: whole file
s: subsitute
.* - : find any text followed by a space a dash and a space.
// : replace it with the empty string.
Stephen
+2  A: 

My solution would be:

qa                 [start recording in record buffer a]
^ (possibly twice) [get to the beginning of the line]
d3f-               [delete everything till - including]
<del>              [delete the remaining space]
<down>             [move to next line]
q                  [end recording]
<at>a              [execute recorded command]

Then just hold <at> until you are done and let automatic key repeat do the work for you.

Note:
Eventhough recorded macros might not always be the fastest and most perfect tool for the job it's often easier to record and execute a macro than to lookup something better.

dbemerlin
It should be `d3f-` because everything up to the *last* (3rd) dash should be deleted. Anyway, very good solution. :-)
Konrad Rudolph
thanks, somehow missed the dashes in the date. post corrected.
dbemerlin
A: 

You can do:

1,$s/.*- //
  • 1: line 1
  • $: last line
  • s: substitution
  • .* : anything

So it replaces on each line anything followed by hyphen and space with nothing.

codaddict
I'd drop the `g` since you only want the substitution to happen once on each line.
Judge Maygarden
@Judge: YOu're right. Thanks :)
codaddict
+5  A: 

You could also use visual block mode to select all the characters you want to delete:

gg        Go to the beginning of the file
Ctrl-v    Enter visual block mode
G         Go to the end of the file
f-        Go to dash
<right>   Go one more to the right
d         Delete the selected block
sth
Shouldn't it be Shift + V to enter visual block mode? Also, it needs to match the third dash, because the timestamps contain two dashes.
John Topley
Shift-v is for visual line mode. Ctrl-v is indeed visual block mode.
Steve S
`Shift + v` (which is `V`) is used to enter the visual line mode.
wRAR
Ah yes, sorry. How do you do Ctrl + v on Windows, which is Paste by default? Do you have to remap the key combo in vimrc?
John Topley
@John: IIRC it's `Ctrl-q` instead of `Ctrl-v` on Windows.
sth
A: 

:%s/.\{-}\ze\d\+,\d\+$//

That command works by anchoring to the comma separated numbers at the end of the line, therefore it works even if everything else but those numbers in the string change.

The visual block way is probably the easiest solution and the one I'd use. But, it doesn't work if the lines were to become staggered, as in:

2010-04-07 14:25:50,772 DEBUG This is a debug log statement - 9,8
2010-04-07 14:25:50,772 DEBUG This is another debug log statement - 9,8

The delimeter might also change to a different character so a line would then look like:

2010-04-07 14:25:50,772 DEBUG This is a debug log statement | 9,8

Then using :%s/.* - // would not work.

Explanation for the regex:

.\{-} matches whatever, excluding newlines, as few as possible

\ze stops matching, so the replace doesn't affect the following characters

\d\+,\d\+$ digits, at least one, followed by a comma, followed by digits, at least one, and the end of line

Naturally it doesn't work if the format of the desired values in the end of the line is erratic, in which case the other solutions work if the lines up to the values are of same length or the delimeters are the same.

Heikki Naski