我正在尝试使用命令行perl替换多行文件中的文本.我正在使用Ubuntu Natty.
以下是我的文本文件(称为test.txt)的内容:
[mysqld]
#
# * Basic Settings
#
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
Run Code Online (Sandbox Code Playgroud)
以下是我的perl命令:
perl -i -pe "s/(\[mysqld\][^\^]+)/\1\nsometext/g" test.txt
Run Code Online (Sandbox Code Playgroud)
但是,下面是我最终得到的内容,而不是替换文件中的所有文本:
[mysqld]
sometext#
# * Basic Settings
#
#
# * IMPORTANT
# If you make changes to …Run Code Online (Sandbox Code Playgroud)