What's the most efficient way to remove the text 2010-04-07 14:25:50,773 DEBUG This is a debug log statement - from a log file like the extract below using Vim?
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 a debug log statement - 1,11 2010-04-07 14:25:50,772 DEBUG This is a debug log statement - 5,2 2010-04-07 14:25:50,772 DEBUG This is a debug log statement - 8,4
This is what the result should look like:
9,8 1,11 5,2 8,4
Note that on this occasion I'm using gVim on Windows, so please don't suggest any UNIX programs which may be better suited to the task—I have to do it using Vim.
Delete All Lines Press the Esc key to go to normal mode. Type %d and hit Enter to delete all the lines.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With