in reply to Re^3: How to print certain lines out of a text file.
in thread How to print certain lines out of a text file.

And here is a snippet of what the text in the file looks like:
Policy Name: BKUP_U_BOX01 Policy Type: Standard Active: yes Effective date: 06/22/2010 11:55:42 Client Compress: no Follow NFS Mounts: no Cross Mount Points: no Collect TIR info: no Block Incremental: no Mult. Data Streams: no Client Encrypt: no Checkpoint: no Policy Priority: 0 Max Jobs/Policy: Unlimited Disaster Recovery: 0 Collect BMR info: no Residence: box08-hcart-robot-acs-0 Volume Pool: box01_Onsite Server Group: *ANY* Keyword: (none specified) Data Classification: - Residence is Storage Lifecycle Policy: no Granular Restore Info: no HW/OS/Client: Solaris Solaris10 box01 Solaris Solaris10 box07 Solaris Solaris10 box08 Include: ALL_LOCAL_DRIVES Schedule: weekly_onsite Type: Full Backup Maximum MPX: 1 Synthetic: 0 PFI Recovery: 0

Replies are listed 'Best First'.
Re^5: How to print certain lines out of a text file.
by repellent (Priest) on Aug 01, 2010 at 05:14 UTC
    You can use the range operator on the command line, like so:
    perl -ne "print if m{^\s*HW/OS/Client:} ... m{^\s*$}" mas01_policy_dum +p.txt

    which tells Perl to go through every line of the given file and print lines in-between (inclusive) two lines which match:
    • first line matches "HW/OS/Client", may begin with optional whitespace
    • last line matches a blank line