无法使用shell脚本在Linux中编辑文件
我正在使用redhat Linux。我正在编写一个脚本,我想在文件中添加一行,然后在下面添加另一行,请告诉我执行该操作的命令。我正在尝试使用sed命令,但这两种情况都没有发生 例如: 在无法使用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
/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