perl -lane更改定界符

发布于 2025-02-09 05:47:01 字数 172 浏览 1 评论 0原文

我有一个班轮:

az account list  -o table |perl -lane 'print $F[0] if /GS/i'

我想将默认分界符从“ \ t”更改为“ - ”

如何做到这一点?

只是想强调,我要寻找的是淘汰;)

I have one liner:

az account list  -o table |perl -lane 'print $F[0] if /GS/i'

I want to change default delimiter from '\t' to '-'

Any hint how to do this?

Just wanted to stress that it is oneliner I look for ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

后eg是否自 2025-02-16 05:47:01

普通-a在任何空格上分配,而不仅仅是选项卡。 -f选项允许您指定其他定界符。

az account list  -o table |
perl -laF- -ne 'print $F[0] if /GS/i'

Plain -a splits on any whitespace, not just tab. The -F option allows you to specify a different delimiter.

az account list  -o table |
perl -laF- -ne 'print $F[0] if /GS/i'
提笔书几行 2025-02-16 05:47:01

perlrun 是告诉您Perl命令行选项的手动页面。它说:

-a

与“ -n”或“ -p”一起使用时,打开自动Pllit模式。 @f数组的隐式拆分命令是隐式内部的第一件事,而“ -n”或“ -p”。

  perl -Ane'打印pop(@f),“ \ n”;'
 

等于

  while(<>){
    @f = split('');
    打印pop(@f),“ \ n”;
}
 

可以使用-f。

指定替代定界符

。和:

-fpattern

指定为“ -a”拆分的模式。该模式可以被//,“” 或''包围,否则将以单引号放入。您不能在模式中使用字面的空格或nul字符。

-f隐式设置“ -a”和“ -n”。

perlrun is the manual page that tells you about Perl's command-line options. It says:

-a

turns on autosplit mode when used with a "-n" or "-p". An implicit split command to the @F array is done as the first thing inside the implicit while loop produced by the "-n" or "-p".

perl -ane 'print pop(@F), "\n";'

is equivalent to

while (<>) {
    @F = split(' ');
    print pop(@F), "\n";
}

An alternate delimiter may be specified using -F.

And:

-Fpattern

specifies the pattern to split on for "-a". The pattern may be surrounded by //, "", or '', otherwise it will be put in single quotes. You can't use literal whitespace or NUL characters in the pattern.

-F implicitly sets both "-a" and "-n".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文