extract only the subroutine names from a perl script

grep -Po '^sub (\w+)' file.pm | cut -d' ' -f2
instead of printing the whole line, print just the capture matched, but with the "cut" pipe :( I'm so sad with grep.
Sample Output
routine_alpha
routine_bravo
routine_charlie

0
2013-03-07 12:31:34

These Might Interest You

  • if I need get olnly script.sh from "folder/script.sh" Show Sample Output


    -3
    tar zxvf package.tar.gz --strip 1
    voyeg3r · 2010-05-18 21:01:23 0
  • This one line Perl script will display the smallest to the largest files sizes in all directories on a server. Show Sample Output


    1
    du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x (1.5*$l),$2);}' | more
    Q_Element · 2012-02-07 15:49:19 0
  • the command show can be run in vim, here is the same thing on the command line cat script.pl | perl -MO=Deparse | perltidy


    3
    %! perl -MO=Deparse | perltidy
    syssyphus · 2009-09-24 03:32:04 0
  • My Programming Languages professor assigned my class a homework assignment where we had to write a Perl interpreter using Perl. I really like Python's interactive command line interpreter which inspired this Perl script.


    10
    perl -e 'while(1){print"> ";eval<>}'
    kzh · 2010-02-03 21:48:33 1

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: