I have a script that I'm using to perform some iptables changes across servers. In the script I have a sed command to find a string and insert iptables rule before that line.
The problem I'm having is that the file I'm editing is a yaml file and I need to have a ' and ' in the line.
If I remove the ' from what I'm inserting, it works.
$ sed 's/.*output_snat_lo.conf:.*/- -t nat -A PREROUTING -d 192.168.1.1 -j DNAT --to-destination 10.0.0.1\n&/' file.yaml
- '-t nat -A POSTROUTING -s 192.168.1.25/32 -d 10.0.0.1 -j SNAT --to-source 172.1.1.1'
- -t nat -A PREROUTING -d 192.168.1.1 -j DNAT --to-destination 10.0.0.1
output_snat_lo.conf:
However, if I try to escape it with slashes or putting it within double quotes, double quotes with slashes I can't get the ' to print but rather give send invalid flag options.
This is what I'm trying to insert.
- '-t nat -A PREROUTING -d 192.168.1.1 -j DNAT --to-destination 10.0.0.1'\n&/' file.yaml
Any suggestions/tricks? I feel like I've done this in the past but can't recall how.