Perl in text formatting


Selecting range of text from a log file, particularly timed data –

perl -ne ‘print if m{^2008-12-22 10:46} .. m{^2008-12-22 11:52}’ log.2008-12-22 >~/20081222-ws02


perl -ne ‘print if m#Full thread# … m#”VM Periodic Task#’ >~/out

Perl is as terse as it is powerful. Here’s a simple substitute command that might come in very handy:

perl -p -i -e ‘s/this/that/g’ filename

This command replaces the string *this* with the string *that* in the specified file — much the same as the scripts recently included in this column.

Just remember that the arguments spell “pie” and that the substitute command looks like a substitute command in sed. Since the command replaces the original file with the changed one, it’s very quick. Arguments:

p print
i in-place edit
e execute the following command

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: