小编yor*_*rgo的帖子

如何将命令输出作为多个参数传递给另一个命令

我想将命令的每个输出作为多个参数传递给第二个命令,例如:

grep "pattern" input
Run Code Online (Sandbox Code Playgroud)

收益:

file1
file2
file3
Run Code Online (Sandbox Code Playgroud)

我想复制这些输出,例如:

cp file1  file1.bac
cp file2  file2.bac
cp file3  file3.bac
Run Code Online (Sandbox Code Playgroud)

我怎么能一气呵成呢?就像是:

grep "pattern" input | cp $1  $1.bac
Run Code Online (Sandbox Code Playgroud)

unix linux shell

7
推荐指数
4
解决办法
5237
查看次数

在解析源代码时,Perl是否根据特定参数进行优化?

Perl是仅在解析源代码期间检查语法错误,还是根据参数/参数进行一些优化?

例如,如果我们运行:

perl source.pl debug=0
Run Code Online (Sandbox Code Playgroud)

在source.pl里面有一个if条件:

if ($debug == 1) {...} else {...} 
Run Code Online (Sandbox Code Playgroud)

"预编译/解析"是否会优化代码,以便跳过"if"检查(当然假设$debug仅在代码的开头等处分配,等等)?

顺便问一下,任何想法,如果TCL这样做?Giorgos

谢谢

perl arguments precompile

1
推荐指数
1
解决办法
77
查看次数

在两个连续行上搜索两个模式并在匹配前打印 n 行

我想使用 shell 命令对匹配两种不同模式的两个连续行进行 grep 或搜索,例如匹配 line1:“abc”,用于 line2:“def”。因此,对于以下文本,应该有一个匹配项:第 4 行和第 5 行。

1234
abc-noise
6789
abc-noise
def-noise
def-noise
1234
Run Code Online (Sandbox Code Playgroud)

当我找到这样的匹配时,我想在匹配之前打印它,包括 N 行。有任何想法吗?谢谢。

linux bash shell grep

1
推荐指数
1
解决办法
4189
查看次数

标签 统计

linux ×2

shell ×2

arguments ×1

bash ×1

grep ×1

perl ×1

precompile ×1

unix ×1