Aloha, I tried to figure out how to replace / insert text strings between two place holders.
REPLACE ANYTHING IN HERE
Initially, I tried to do this using BASH via sed, but hit the road block when I tried to pass the sed variable.
sed -n -i '/
Returns
hello
but without joy when I try
sed -n -i '/#start/{p;:a;N;/#end/!ba;s/.*\n/$replace_var\n/};p' file.txt
or
sed -n -i "/#start/{p;:a;N;/#end/!ba;s/.*\n/$replace_var\n/};p" file.txt
I was in this for hours and searched, but could not find a solution. I want to try python or another language, or maybe with awk. I am a little new in this world, so any useful information would be appreciated.
Thanks in advance
This is what I went with at the end. This is a script that, along with cron, updates the /var/etc/hosts.deny file with the latest ssh list published.
import re
import urllib2
hosts_deny = open('/etc/hosts.deny','r+')
hosts_deny_text = hosts_deny.read()
blockedHosts = urllib2.urlopen('http://www.openbl.org/lists/hosts.deny').read()
place = re.compile('(?<=
'(.*?)'
'(?=\r?\n
hosts_deny_text = re.sub(place, '\n'+ blockedHosts, hosts_deny_text)
hosts_deny.seek(0)
hosts_deny.write(hosts_deny_text)
hosts_deny.close()
jason source
share