小编sac*_*hin的帖子

如何使sed从文件中读取其脚本?

最近我遇到了以下grep命令:

/usr/xpg4/bin/grep -Ff grep.txt input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)

根据我的理解,这意味着从input.txt中,grep grep.txt中包含的内容并将其输出到output.txt.

我想为sed做类似的事情,即我想将sed命令保存在一个单独的文件中(比如sed.txt),并希望将它们应用于输入文件(比如input.txt)并创建一个输出文件(比如output.txt) ).

我试过以下:

/usr/xpg4/bin/sed -f sed.txt input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)

它不起作用,我收到以下错误:

sed: command garbled
Run Code Online (Sandbox Code Playgroud)

上述文件内容如下:

sed.txt

sed s/234/acn/ input.txt
sed s/78gt/hit/ input.txt
Run Code Online (Sandbox Code Playgroud)

input.txt中

234GH
5234BTW
89er
678tfg
234
234YT
tfg456
wert
78gt
gh23444
Run Code Online (Sandbox Code Playgroud)

unix sed

21
推荐指数
2
解决办法
3万
查看次数

使用perl创建层次结构文件

我的任务是使用perl创建父子层次结构文件.

示例输入文件(制表符分隔).记录将以随机顺序排列在文件中,"父"可以出现在"子"之后.

 S5 S3
 S5 S8
 ROOT   S1
 S1 S7
 S2 S5
 S3 S4
 S1 S2
 S4 77
 S2 S9
 S3 88
Run Code Online (Sandbox Code Playgroud)

示例输出文件(制表符分隔)

ROOT    S1  S2  S5  S3  S4  77
ROOT    S1  S2  S5  S3  88
ROOT    S1  S7
ROOT    S1  S2  S5  S8
ROOT    S1  S2  S9
Run Code Online (Sandbox Code Playgroud)

生成上述输出文件的代码

use strict;

# usage: perl parent_child_generator.pl input.txt output.txt

my $input0=$ARGV[0] or die "must provide input.txt as the first argument\n";
my $output1=$ARGV[1] or die "must provide output.txt as the second argument\n";

open(IN0,"<",$input0) …
Run Code Online (Sandbox Code Playgroud)

perl

5
推荐指数
2
解决办法
1539
查看次数

if语句中的Eval

如何在perl if语句中动态传递eq或ne?我在下面尝试但是没有工作:

my $this="this";
my $that="that";
my $cond='ne';
if($this eval($cond) $that)
{
  print "$cond\n";
}
Run Code Online (Sandbox Code Playgroud)

perl

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

标签 统计

perl ×2

sed ×1

unix ×1