Main Page | Report this Page
 
Computers Forum Index  »  Computer - Editors  »  vim substitution...
Page 1 of 1    

vim substitution...

Author Message
Andy...
Posted: Thu Sep 24, 2009 2:23 pm
Guest
Hi there,

Imagine we have a text file with the following content:

"1st Jan","First day"
"2nd Jan",""Second day"
"3rd Jan","Third day"
"4th Jan","Fouth day"

and we want to remove the date suffixes "st, nd, rd and th" to get:

"1 Jan","First day"
"2 Jan",""Second day"
"3 Jan","Third day"
"4 Jan","Fouth day"

In vim is it possible to do a substitution along the lines of:
:%s/[0-9][a-z][a-z]/[0-9]/g

this will replace the number with [0-9]. Is it possible to get vim to
leave the number as it is?

Many thanks

Andrew
 
Andrew 2006...
Posted: Thu Sep 24, 2009 3:07 pm
Guest
Found the answer here:
http://vim.wikia.com/wiki/Special_characters_in_the_substitute_command

:%s/\(\"\d\+\)[a-z][a-z]/\1/gc
 
Christian Brabandt...
Posted: Thu Sep 24, 2009 11:44 pm
Guest
On 2009-09-24, Andrew 2006 <mymatebob at (no spam) googlemail.com> wrote:
Quote:
Found the answer here:
http://vim.wikia.com/wiki/Special_characters_in_the_substitute_command

:%s/\(\"\d\+\)[a-z][a-z]/\1/gc
:%s/^"\d\zs\%(st\|nd\|rd\|th\)//


regards,
Christian
--
Time is money. Especially if you make clocks.
 
Peter Gordon...
Posted: Thu Oct 01, 2009 5:05 am
Guest
Andy <mymatebob at (no spam) googlemail.com> wrote in news:3e310264-6da8-4dde-ab60-
77dba9aa8d36 at (no spam) q14g2000vbi.googlegroups.com:

Quote:
"1st Jan","First day"
"2nd Jan",""Second day"
"3rd Jan","Third day"
"4th Jan","Fouth day"


Use:
:%s/\(\"[0-9]*\)[A-Za-z]* \(.*\)/\1 \2/
 
 
Page 1 of 1    
All times are GMT
The time now is Sun Nov 22, 2009 3:52 am