我想通过perl命令行(perl命令行必须在我的bash脚本中)在文件中添加PATH – / usr / local / bin / perl befporestring,我有solaris机器
在$ APIDIR / scan.pl文件之前和char之后添加 – / usr / local / bin / perl目标 – “
请咨询如何在$ APIDIR / scan.pl之前添加PATH – / usr / local / bin / perl ,最后我会得到
新线 –
my $APIDIR="/usr/local/cp/api"; remark - this line shouldn't be change my $script="/usr/local/bin/perl $APIDIR/scan.pl";
代替
my $APIDIR="/usr/local/cp/api"; my $script="$APIDIR/scan.pl";
我尝试以下但不改变行:
[root@machine1a /var/tmp]# perl -p -i -e 's/\/usr\/local\/bin\/perl \$APIDIR\/scan.pl/\$APIDIR\/scan.pl/g' file [root@machine1a /var/tmp]# more file my $APIDIR="/usr/local/cp/api"; my $script="$APIDIR/scan.pl";
你可以用sed来做这件事
sed 's|$APIDIR/scan.pl| /usr/local/bin/perl $APIDIR/scan.pl|' file >file.new
或与Perl
perl -p -i -e 's|$APIDIR/scan.pl| /usr/local/bin/perl $APIDIR/scan.pl|' file
所以你想用/ usr / local / bin / perl $ APIDIRreplace$ APIDIR? 如果是这样,你的正则expression式是落后的。 你想要的东西像:
s/\$APIDIR\/\/usr\/local\/bin\/perl $APIDIR/
所以试试:
perl -p -i -e 's#\$APIDIR#\/usr\/local\/bin\/perl \$APIDIR#g' file
我希望这是你以后的事情,