sed 未终止的地址正则表达式
sed unterminated address regex
以下 sed 命令在终端中有效,但当我想将输出存储到脚本中的变量中时,它提示我“sed:-e 表达式 #1,字符 27:未终止的地址正则表达式”消息。不知道这是什么...
Input file example:
orange
abc
def
apple
asd
edf
sed 命令获取关键字直到 brank 行,这在终端中有效:
sed -n '/orange/,/^$/p' temp_stage.txt
使用确切的命令存储到变量中。不工作。
my $waha = `sed -n '/orange/,/^$/p' temp_stage.txt`;
这是一个完全不使用 sed
的版本。
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'temp_stage.txt';
my $waha;
open my $fh, $filename or die("[=10=]: $filename: $!");
while(<$fh>) {
# concatenate the lines from "orange" to blank (inclusive)
$waha .= $_ if(/orange/ .. /^$/);
}
close($fh);
print "$waha";
有关用于捕获范围的 ..
运算符,请参阅 perlop - Range-Operators。
以下 sed 命令在终端中有效,但当我想将输出存储到脚本中的变量中时,它提示我“sed:-e 表达式 #1,字符 27:未终止的地址正则表达式”消息。不知道这是什么...
Input file example:
orange
abc
def
apple
asd
edf
sed 命令获取关键字直到 brank 行,这在终端中有效:
sed -n '/orange/,/^$/p' temp_stage.txt
使用确切的命令存储到变量中。不工作。
my $waha = `sed -n '/orange/,/^$/p' temp_stage.txt`;
这是一个完全不使用 sed
的版本。
#!/usr/bin/perl
use strict;
use warnings;
my $filename = 'temp_stage.txt';
my $waha;
open my $fh, $filename or die("[=10=]: $filename: $!");
while(<$fh>) {
# concatenate the lines from "orange" to blank (inclusive)
$waha .= $_ if(/orange/ .. /^$/);
}
close($fh);
print "$waha";
有关用于捕获范围的 ..
运算符,请参阅 perlop - Range-Operators。