Home > other >  perl -lane change delimiter
perl -lane change delimiter

Time:06-21

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 ;)

CodePudding user response:

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'

CodePudding user response:

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".

  • Related