Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用shell脚本在Linux中编辑文件_Shell_Unix_Scripting - Fatal编程技术网

无法使用shell脚本在Linux中编辑文件

无法使用shell脚本在Linux中编辑文件,shell,unix,scripting,Shell,Unix,Scripting,我正在使用redhat Linux。我正在编写一个脚本,我想在文件中添加一行,然后在下面添加另一行,请告诉我执行该操作的命令。我正在尝试使用sed命令,但这两种情况都没有发生 例如: 在/etc/ssh/sshd_config文件中,我想在ClientAliveCountMax 0和之前添加ClientAliveCountMax 3 sed 's/ClientAliveCountMax 0/ClientAliveCountMax 3 \ #ClientAliveCountMax 0/g' /e

我正在使用redhat Linux。我正在编写一个脚本,我想在文件中添加一行,然后在下面添加另一行,请告诉我执行该操作的命令。我正在尝试使用sed命令,但这两种情况都没有发生

例如: 在
/etc/ssh/sshd_config
文件中,我想在
ClientAliveCountMax 0
之前添加
ClientAliveCountMax 3

sed 's/ClientAliveCountMax 0/ClientAliveCountMax 3 \
 #ClientAliveCountMax 0/g' /etc/ssh/sshd_config
sed 's/\(ClientAliveCountMax.*\)/ClientAliveCountMax 3 \
#\1/' /etc/ssh/sshd_config 
使用GNU awk

awk '/ClientAliveCountMax/{$0="ClientAliveCountMax 3\n#"$0}1' /etc/ssh/sshd_config 

有一个不适合你的代码片段吗?
awk '/ClientAliveCountMax/{$0="ClientAliveCountMax 3\n#"$0}1' /etc/ssh/sshd_config