Search |
||
groovy -pi -ePosted by tomwhite on April 18, 2005 at 12:55 PM PDT
Perl is famous for its one-liners. By using the perl -pi -e 's/curious george/the gruffalo/g' favourites.html
I was happy to learn recently that you can do the same with Groovy. Groovy supports the same set of command line arguments, but the script is obviously more Java-ish (the
groovy -pi -e "(line =~ 'curious george').replaceAll('the gruffalo')" favourites.html
OK, it's not quite as terse, but it's still a one-liner. (Actually, there is a bug in the latest version of Groovy, JSR 1, which prevents the
More complicated examples provide a great way to learn more about Groovy features. This
groovy -pe "line.split('\\s')[0, -2]" *
And this will find duplicate words: groovy -ne "if (line =~ '\\b(\\w+)\\b\\s+\\b\\1\\b') println line" * Do you have any Groovy one-liners? »
Related Topics >>
Programming Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|