2010-10-21

Perl one-liner: listing command line arguments one line at a time.

You know how Java application servers have loads of command line arguments? And every once in a while you want to list all those arguments one line at a time?

In other words, you want a perl version of using tr to change spaces to newlines.

ps -ef | grep appServerName | tr '[:space:]' '[\n*]'

Here is one way. This lends itself to extending the one-liner for processing the args in some way via @F.

ps -ef | perl -lane 'print join("\n", @F) if $F[-1] =~ /appServerName/'

Here is another.

ps -ef | perl -ne 'next unless /appServerName/; s/\s+/\n/g; print;'

No comments:

Post a Comment