Ok I 认为我需要做以下工作:
查阅<代码>/var/lib/asterisk/bin/retrieve_conf中的这一条码:
$engineinfo = engine_getinfo();
插入以下两行:
$engineinfo[ engine ]="asterisk";
$engineinfo[ version ]="1.6.2.11";
Thanks in advance, Joe
Ok I 认为我需要做以下工作:
查阅<代码>/var/lib/asterisk/bin/retrieve_conf中的这一条码:
$engineinfo = engine_getinfo();
插入以下两行:
$engineinfo[ engine ]="asterisk";
$engineinfo[ version ]="1.6.2.11";
Thanks in advance, Joe
你可以这样做。
sed -ne /$engineinfo = engine_getinfo();/a $
$engineinfo[ engine ]="asterisk"; $
$engineinfo[ version ]="1.6.2.11"; $
;p /var/lib/asterisk/bin/retrieve_conf
添加“代码>-i,以便在你确认其运作后加以修改。
它做了哪些工作?
第一,我们听起来说,要看一线,包括你的扼杀。 届时,我们将执行<条码>a条码>指令,即“附录案文”。
缩略语 指挥
a
line of text
another line
;
Note that the literal newlines are part of this syntax. To make it all one line (and preserve copy-paste ability) in place of literal newlines I used $
which will tell bash or zsh to insert a real newline in place. The quoting necessary to make this work is a little complex: You have to exit single-quotes so that you can have the $
be interpreted by bash, then you have to re-enter a single-quoted string to prevent bash from interpreting the rest of your input.
EDIT: 更新,以对两条线进行对应指挥。
http://perldoc.perl.org/Tie/File.html (列入伯尔分发文件):
use Tie::File;
tie my @array, Tie::File , "/var/lib/asterisk/bin/retrieve_conf" or die $!;
for (0..$#array) {
if ($array[$_] =~ /$engineinfo = engine_getinfo();/) {
splice @array, $_+1, 0, q{$engineinfo[ engine ]="asterisk"; $engineinfo[ version ]="1.6.2.11";};
last;
}
}
就是为了这里的不对称,我们用一刀回答。
awk { if(/$engineinfo = engine_getinfo();/) print $0"
$engineinfo[ engine ]="asterisk";
$engineinfo[ version ]="1.6.2.11"" ; else print $0 } in.txt
也可使用<条码><>。
# cf. http://wiki.bash-hackers.org/howto/edit-ed
cat <<- EOF | ed -s /var/lib/asterisk/bin/retrieve_conf
H
/$engineinfo = engine_getinfo();/a
$engineinfo[ engine ]="asterisk";
$engineinfo[ version ]="1.6.2.11";
.
wq
EOF
A Perl one-liner:
perl -pE s|($engineinfo) = engine_getinfo();.*K|
${1}[ engine ]="asterisk";
${1}[ version ]="1.6.2.11";| file
sed -i s/$engineinfo = engine_getinfo();/$engineinfo = engine_getinfo();<CTRL V><CNTRL M>$engineinfo[ engine ]="asterisk"; $engineinfo[ version ]="1.6.2.11";/ /var/lib/asterisk/bin/retrieve_conf
I am building a Web interface to monitor an embedded system. I have built a Perl script which runs remote commands and gathers output from that system. Now what I need is a Web interface which makes ...
How do I tell what type of value is in a Perl variable? $x might be a scalar, a ref to an array or a ref to a hash (or maybe other things).
When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...
I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...
I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...
I would like to submit a form to a CGI script localy (w3c-markup-validator), but it is too slow using curl and apache, I want to use this CGI script more than 5,000 times in an another script. and ...
So I m running perl 5.10 on a core 2 duo macbook pro compiled with threading support: usethreads=define, useithreads=define. I ve got a simple script to read 4 gzipped files containing aroud 750000 ...
A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...