Replace 从url复制并粘贴到文件中以替换某些内容的脚本
我正在尝试制作一个脚本,该脚本将自动复制WordPress API服务的全部内容,并将其粘贴到wp-config.php中,替换现有行:Replace 从url复制并粘贴到文件中以替换某些内容的脚本,replace,find,multiline,Replace,Find,Multiline,我正在尝试制作一个脚本,该脚本将自动复制WordPress API服务的全部内容,并将其粘贴到wp-config.php中,替换现有行: 45: define('AUTH_KEY', 'put your unique phrase here'); 46: define('SECURE_AUTH_KEY', 'put your unique phrase here'); 47: define('LOGGED_IN_KEY', 'put your unique phrase
45: define('AUTH_KEY', 'put your unique phrase here');
46: define('SECURE_AUTH_KEY', 'put your unique phrase here');
47: define('LOGGED_IN_KEY', 'put your unique phrase here');
48: define('NONCE_KEY', 'put your unique phrase here');
49: define('AUTH_SALT', 'put your unique phrase here');
50: define('SECURE_AUTH_SALT', 'put your unique phrase here');
51: define('LOGGED_IN_SALT', 'put your unique phrase here');
52: define('NONCE_SALT', 'put your unique phrase here');
最好的方法是什么?阿鲁塔库帮我解释了他对wget的暗示。我仍然不认为这个解决方案是完美的(我将在下面解释原因),我想看看是否有人有任何其他的建议。但这仍然是一个有效的选择。所以,我的剧本:
# Delete lines from 45 to 52 from wp-config.php
sed -i 45,52d wp-config.php
# Get new lines and save them in a temporary file
curl https://api.wordpress.org/secret-key/1.1/salt/ > temp-salt
# Insert temporary file content into wp-config.php after line 44
sed -i '44r temp-salt' wp-config.php
# Delete the temporary file
rm temp-salt
缺点是该脚本使用行号而不是行内容进行操作,这就是它不够完美的原因。但是
wp content sample.php
文件不太可能经常更改,所以我想它也不坏。你能用wget从它的URL获取文件吗?@arutaku我可以,但我不需要这个文件,我需要它的内容。我需要复制该文件的全部内容,粘贴到另一个文件中,并从第二个文件中删除这些其他行。@arutaku实际上,你的提示帮助了我。我马上回答我自己的问题。听起来不错。作为建议,您可以使用wget-O-将网页作为输入流获取,并避免使用临时文件;-)酷,我不知道。谢谢。