mir*_*rza 0 php wordpress bash sed
我试图在wordpress php文件define('WP_MEMORY_LIMIT', '96M');后添加define('WP_DEBUG', false);.
这是我到目前为止尝试的内容:
1-
sed -b -i "/'WP_DEBUG', false);/a define('WP_MEMORY_LIMIT', '96M');" $full_path/wp-config.php;
Run Code Online (Sandbox Code Playgroud)
2-
sed -i "s/'WP_DEBUG', false);/'WP_DEBUG', false);\ndefine('WP_MEMORY_LIMIT', '96M');/" $full_path/wp-config.php;
Run Code Online (Sandbox Code Playgroud)
问题是,所有新行都被这个回车符替换.如何在特定行之后添加新行并且没有此问题?
define('WP_DEBUG', false);^M
define('WP_MEMORY_LIMIT', '96M');
Run Code Online (Sandbox Code Playgroud)
使用sed(GNU sed)4.2.2,Ubuntu 16.04
以下是澄清问题的屏幕截图:
注意: Okey,问题在阅读@ anishsane的答案后解决了.由于原始文件(来自wordpress.org/latest.zip)具有CRLF(windows)行结尾,因此添加\n正在打破文件视图.使用"\ r \n"解决了这个问题:
sed -i "s/'WP_DEBUG', false);/'WP_DEBUG', false);\r\ndefine('WP_MEMORY_LIMIT', '96M');/" $full_path/wp-config.php;
Run Code Online (Sandbox Code Playgroud)
我不确定为什么会掉线.请解释一下,所以我可以澄清这个问题.
该文件最初具有CRLF行结尾.当您在vim编辑器中打开它时,vim会理解该文件具有CRLF结尾并将其隐藏在用户之外.通过编辑器添加的任何新行也将具有与文件其余部分相同的行结尾.
当您添加新行时sed,它有LF行结尾.下次打开时vim,vim会看到混合行结尾,CRLF&LF.vim然后决定将其解释为带有LF行尾的文件.&所有CR字符都突出显示为^M.
测试,试试这个:
$ printf '%d\r\n' {1..5} > test_endings # This will create a file with CRLF endings.
$ file test_endings
test_endings: ASCII text, with CRLF line terminators
$ vim test_endings
1
2
3
4
5
~
~
"test_endings" [dos] 5L, 15C <~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Notice the word DOS here.
$ echo 6 >> test_endings # This will add line with LF line endings.
$ file test_endings
test_endings: ASCII text, with CRLF, LF line terminators
$ vim test_endings
1^M
2^M
3^M
4^M
5^M
6
~
~
"test_endings" 6L, 17C
Run Code Online (Sandbox Code Playgroud)
简而言之,问题不在于sed,它与原始文件有关.
| 归档时间: |
|
| 查看次数: |
1827 次 |
| 最近记录: |