tags:

views:

1093

answers:

2

I am trying to search a text file for a certain pattern. If this pattern occurs then it means that the rest of the line is not needed and therefore can be deleted.

I have tried using the following commands, but so far have been unsuccessful.

:%s/{pattern}/d$

:g/{pattern}/d$

If anyone has any suggestions they would be greatly appreciated

thanks

+4  A: 

would :%s/{pattern}.*// work?

mirod
yep that works great, thank you
smauel
+7  A: 

Alternatively, the following also works

:g/{pattern}/normal nd$

For what you want, I would go with mirod's suggestion. What I posted is a bit more flexible and might come in handy in similar situations.

Explanation:

On each line, where pattern matches, execute the following normal mode commands 'nd$'. With the cursor at the start of the line, 'n' jumps to the pattern, and 'd$' deletes to the end of the line.