有 Perl 替代剪切和粘贴 shell 命令吗?
我曾经看到过一个用于剪切和粘贴 Linux 命令的快速但肮脏的 Perl 实现。这就像 perl '打印“$F1”'文件名
替换 cut -f1 filename 命令
有人能告诉我 Perl 的方式是怎样的吗?具体来说,我很感兴趣,因为与剪切/粘贴不同,它在 Windows 环境中也能起到同样的作用。
I saw once a quick and dirty Perl implementation for the cut and paste linux commands. It was something likeperl 'print "$F1"' filename
to substitute a cut -f1 filename command
Can someone tell me how was this Perl way? Specifically, I'm interested because this, unlike cut/paste, will work the same also in Windows environments.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您了解 Perl 电动工具吗?它们是您最喜欢的 UNIX 命令的实现,但是是用 Perl 完成的。如果您有 Perl,您就可以使用您最喜欢的命令,而无需在命令行上进行杂技操作。 PPT 具有
剪切
和粘贴
功能。尽管许多人向您指出了一些
perl
开关,但他们忘记链接到 perlrun< /a> 这解释了所有这些。Do you know about the Perl Power Tools? They are implementations of your favorite unix commands, but done in Perl. If you have Perl, you can have your favorite commands without acrobatics on the command line. PPT has both
cut
andpaste
.Although many people pointed you to some
perl
switches, they forget to link to perlrun which explains them all.cut
要提供自定义输入分隔符,
要更改输出分隔符,
要在使用时使用
grep
进行粘贴
不太容易。
cut
To give a custom input separator,
To change the output separator,
To
grep
while you're at it,paste
Not quite as easy.
对于剪切:我认为您正在寻找
perl -ane
解决方案(-e
执行以下代码,-an
应用@F = split (/\t/,$line)
到文件中的每一行)。因此,类似于:
与:
对于粘贴,我不确定如何执行此操作,但我认为
perl -ane
可以将多个文件作为输入。For cut: I think you are looking for the
perl -ane
solution (the-e
executes the following code, the-an
applies@F = split (/\t/,$line)
to every line in the file).So something like:
which is identical to:
For paste, I'm not sure how you can do this, but I think the
perl -ane
can take multiple files as input.Perl 相当于 cut -c1-2
perl -alne 'print substr($_,0,2)'
Perl equivalent of cut -c1-2
perl -alne 'print substr($_,0,2)'