【发布时间】:2019-02-26 11:19:01
【问题描述】:
我有一个文件 test.txt,内容如下:
one
two
three
现在,我想按如下方式打印该文件的每一行:
.one (one)
.two (two)
.three (three)
我在 Perl 中试试这个:
@ARGV = ("test.txt");
while (<>) {
print (".$_ \($_\)");
}
这似乎不起作用,这就是我得到的:
.one
(one
).two
(two
).three
(three
)
有人能帮我找出问题所在吗?
更新:
感谢 Aureliano Guedes 的建议。
这个 1-liner 似乎工作:
perl -pe 's/([^\s]+)/.$1 ($1)/'
【问题讨论】:
-
@Biffen 请不要在 cmets 中回答。
标签: perl