January 19, 2012
filed mid-morning by dr_who in: hacking
average time to read 0:32 minutes

the other day i was coding a scala apply(array: Array[String}) method to instantiate an object from a CSV file. i ended up with something like this:

there were about a 100 parameters to use. i wasn’t really too excited about having to change the rewired(0) to use the proper index by hand. so, here’s what i did:

  • in emacs mark the region
  • then invoke shell-command-on-region and
  • use perl -pi -e 's{rewired(0)}{sprintf("rewired(%d)", $. - 1)}e;' as command to invoke

emacs will then show you the result of the command in a temporary buffer, you can either copy and paste from there, or just repeat the shell-command-on-region and prefix it with ctrl-u — emacs with then replace the region with the output of the command directly.


all content posted on these pages is an expression of my own mind. my employer is welcome to share these opinions but then again he might not want to.


  1. I find keyboard macros nice for things like this (spaces add for readability).

    “M-0 C-x r n a” put the number zero in register a

    “C-x (” begin keyboard macro

    “C-s rewired(0) C-b C-b C-d” search for rewired(0), go back to spaces and erase the 0

    “C-x r i a” insert the value of the a register

    “C-x r + a” increment the value of the a register

    “C-x )” end keyboard macro

    “M-10 C-x e” execute that macro ten times

    comment by James — January 22, 2012 @ 14:35

  2. cool! learned something again! :-) apologies for late reply, just realized blog related email was going to that forgotten account. d’oh.

    comment by dirk husemann — February 21, 2012 @ 19:39

RSS feed for comments on this post. TrackBack URI

Leave a comment