我正在尝试使用命令行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
以下是我的 Perl 命令:
perl -i -pe "s/(\[mysqld\][^\^]+)/\1\nsometext/g" test.txt
但是,我最终得到的结果并不是替换文件中所有文本,而是以下内容:
[mysqld]
sometext#
# * 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
#
我在RegexBuddy工具中为Perl尝试了正则表达式,它匹配了文本文件中的所有内容,但出于某种原因,使用命令行中的Perl时它不起作用。
我需要一些帮助。
提前感谢您的帮助。