DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Group Substitution in Vim


The origin text is:

sqoop export --columns int_id,date_time,mr_count,ecno_pollution,rscp_0,rscp_1,rscp_2,rscp_3,rscp_4,rscp_5,load_time --input-field

The target text is:

sqoop export --columns int_id,date_time,mr_count,ecno_pollution,rscp0,rscp1,rscp2,rscp3,rscp4,rscp5,load_time --input-field

We want remove all underscore in "rscp_3", which means converting it to "rscp3". The real text has ninety more items, so we can't do substitutions manually. And other items also use underscore, so you can't only remove all underscores.

Solution: :s/rscp_\(\d\+\)/rscp\1/gc.

We use "(" and ")" to mark a group, use "\1" to represent it in the new strings.



Published

Jun 13, 2014

Last Updated

Jun 13, 2014

Category

Tech

Tags

  • substitution 2
  • vim 92

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor