複雑な行の前後に複雑な行を挿入する

複雑な行の前後に複雑な行を挿入する

複雑なテキストを含むファイルがあります。

    print("ERROR: passwords don't match")

password = hash_func(password.encode("UTF-8")).hexdigest()

間にこのテキストを挿入する必要があります。

with open('/etc/openvpn/clients/%s/login.txt' % username, 'w') as login_log:
    login_log.write('%s\n%s\n' % (username, password))

それではこうなります。

 else:
        print("ERROR: passwords don't match")


with open('/etc/openvpn/clients/%s/login.txt' % username, 'w') as login_log:
    login_log.write('%s\n%s\n' % (username, password))

password = hash_func(password.encode("UTF-8")).hexdigest()

ベストアンサー1

cat > user.inp << EOL

with open('/etc/openvpn/clients/%s/login.txt' % username, 'w') as login_log:
    login_log.write('%s\n%s\n' % (username, password))
EOL
sed -i '/ERROR: passwords/r user.inp' /root/add.py
fi

おすすめ記事