Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend two new lines before additional text using sed
    primarykey
    data
    text
    <p>I've hit a bit of a stumper (for me). I'm attempting to insert two newline characters into the RHEL5 /etc/sysconfig/iptables file during our server build process (using kickstart post-installation scripts).</p> <p>The specific sed command is:</p> <pre><code>${SED} -i "/-i lo/ a\ \n\n#Trusted Traffic\n-A INPUT -s 10.153.156.0/25,10.153.174.160/27 -d ${MGTIP} -m state --state NEW -j ACCEPT\n\n#Remote Access\n-A INPUT -s 10.120.80.0/21,10.152.80.0/21,10.153.193.0/24,172.18.1.0/24,${MGTNET}/${NUMBITS} -d ${MGTIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n#Backups\n-A INPUT -s 10.153.147.192/26 -d ${BKPIP} -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT\n\n" ${IPTABLES} </code></pre> <p>This is actually part of a larger script. ${SED}and ${IPTABLES} are already set to the necessary values.</p> <p>All of the newlines work with the exception of the first two. Or, more accurately, the second of the first two. Even the last two newlines after ACCEPT work. What happens with the first two newlines is that the first works, creating a newline after matching the iptables entry which contains <code>-i lo</code>. The second, however, simply inserts a literal 'n' prior to the <code>#Trusted Traffic</code> text.</p> <p>It ends up looking like</p> <pre><code>(snip) -A RH-Firewall-1-INPUT -i lo -j ACCEPT n#Trusted Traffic -A INPUT (snip) </code></pre> <p>I've tried various methods of ensuring the second newline is inserted. I've used two blank lines instead of <code>\n\n</code>. I've used two newline characters on separate lines, I've used <code>\\n\\n</code>. Everything I've tried so far results in the same outcome: A literal 'n' being inserted instead of a second newline.</p> <p>Does sed simply not work with two newline characters at the beginning of appended text? Is there a way to make this work that I'm simply ignorant of?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload