Reputation: 457
I have a text file with about 2,000 lines of text and I want to remove a large portion of each line of text.
The text is in this format:
Important Text that I care about. Stuff I want to delete
I am unsure as to how to delete all of the text after the .
in each line.
Can someone give me a quick command that would do this?
Upvotes: 34
Views: 60162
Reputation: 4660
Use the Substitution Ex Command to Trim All Lines
This is very similar to both answers, yet I think there is value in presenting it.
Like the other answers, I just used the ex substitution command:
:%s/[^.]*$//
Explanation of substitution:
%
indicates a range for all lines.
[^.]
is a character class of all non-period characters
*
is a quantifier indicating 0 or more matches.
$
is an anchor which communicates to VIM that we want this pattern to match at the end of the line.
Addendum
The solution assumes each line will have a period, otherwise the command will not work as expected as @Qeole has indicated. Qeole's solution addresses non-periods lines appropriately.
Upvotes: 11
Reputation: 802
with the cursor at the first character of first line.
fS<Ctrl-V>G$d
Upvotes: 1
Reputation: 196886
Various additional :normal
solutions:
:%norm )Dx
:%norm $T.D
:%norm f.C.
:%norm 0/\. /e<C-v><CR>D
Upvotes: 31
Reputation: 559
Use search and replace
"vim feature" combined with regex:
:%s/\..*$//g
Upvotes: 2