I'm settling down to work through the suggestions so far, but I think I could usefully go into a bit more detail now that I've got a better idea of formatting etc. My apologies, I've been an occasional lurker for years but haven't barked before.

What I'm trying to do is take a pattern of some sort, and then to "hiccough" some (but not all) of the lines an indeterminate number of times. So on reflection- and my apologies for not being more explicit first time round- this might be a better example of the required output:

iptables -t nat -N outbound-DMZ iptables -t nat -A outbound-DMZ -o eth1.201 -j SNAT --to-source 90.145 +.84.155 iptables -t nat -A outbound-DMZ -o eth1.200 -j SNAT --to-source 90.145 +.84.155 iptables -t nat -A outbound-DMZ -j RETURN iptables -t nat -A POSTROUTING -j outbound-DMZ

where this shows that the repeated lines are typically in the middle of the block of text rather than at the beginning or end. One idea that occured to me was something like

$commands = &reinterpolate <<"EOF"; iptables -t nat -N outbound-DMZ foreach \$iface (keys \%ipAddress) { iptables -t nat -A outbound-DMZ -o \$iface -j SNAT --to-source \$ipA +ddress{\$iface} } iptables -t nat -A outbound-DMZ -j RETURN iptables -t nat -A POSTROUTING -j outbound-DMZ EOF

where &reinterpolate picks up the lines with and between braces and (eventually) applies eval(), but I can see that some of the suggestions are approaching that.

The system this would be running on is a minimal router, so if possible I'd like to avoid anything that isn't in a typical Linux distro.

MarkMLl

In reply to Re: hiccoughing here documents by Anonymous Monk
in thread hiccoughing here documents by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.