I am trying to use VIM to replace all the characters up to the first comma in a large text file (10mb+)
I have something that looks like:
foo,bar,sun
apple,pear,goose
monkey,pig,baby
and I want it to look like:
bar,sun
pear,goose
pig,baby
The following should do it
:%s/^[^,]*,//
Explanation:
Alternatively you can use sed:
sed 's/^[^,]*,//' -i FILENAME
or
sed 's/^[^,]*,//' FILENAME > NEWFILENAME
Edit: minor formatting and explain ":"
You can use
:%norm df,
to run the normal command df,
on every line in the file. Which deletes from the beginning of the line up to and including the first comma.
Read :help :normal
This should do it:
[esc]:%s:^[^,]*,::
edit: of course you can also use cut:
cut -d , -f 2- < mybigfile.txt > newfile.txt
:%s/.\{-},//
This version uses a non-greedy quantifier \{-}
which causes the preceding dot to be matched 0 or more times but as few as possible (hence it is non-greedy).
This is similar to using a *?
in most other regular expression flavors.
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