TimM has asked for the wisdom of the Perl Monks concerning the following question:

(Please note that I'm new to Perl.)

Let's say I have something like this (this is only an example, actual request will be different:

http://pastebin.org/58143

And I want to remove all responses and all one liners showing page address. I would like to only have all requests left in text file with saved LiveHTTPHeaders output.

So, the output would be:

http://pastebin.org/58144

I want to remove useless (for my task) information that tool (livehttpheaders) is generating. Could someone suggest how to do it? I have script I'm trying to use for this but its output is empty file instead of what I'm trying to achieve. Script looks like this (If you would like to suggest something completely different it's ok):
#!/usr/bin/perl local $/ = "\n\n"; while (<>) { print if /^GET|POST/; # Add more request types as needed }
  • Comment on How can I remove responses from Firefox LiveHTTPHeaders output using Perl?
  • Download Code

Replies are listed 'Best First'.
Re: How can I remove responses from Firefox LiveHTTPHeaders output using Perl?
by zwon (Abbot) on Nov 28, 2009 at 22:29 UTC
    perl -e'while(<>){print if /^(GET|POST)/../^\r?$/;}' <58143.txt
Re: How can I remove responses from Firefox LiveHTTPHeaders output using Perl?
by Anonymous Monk on Nov 28, 2009 at 20:31 UTC

    The alternator | in the regex binds before the anchor ^ does. So you really meant /^(?:GET|POST)/, where (?:foo) is a non-capturing group which matches "foo".

    Also, judging by the second paste, there may be leading whitespace on each line. You can use in any case the pattern /^\s*(?:GET|POST)/, where \s* matches zero or more space characters before "GET" or "POST" (be they regular space or character code 32, tab, or whatever; except for newlines, because that requires a separate flag).

    For the relevant documentation, see perlretut and perlre.