Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl command line autosplit vs / /

Tags:

perl

I frequently use Perl autosplit instead of cut on the command line. I have hit a case where I have a lot of blanks that I need to preserve. According to the doc, the separator I need to specify is / / because things like ' ' emulate awk's behavior stripping leading blanks etc.

My problem is it seems impossible to specify the / / pattern on the command line. I tried quoting it in various ways but splitting end up occuring on the forward slash:

perl -F'/ /' -lane 'print "@F[3..$#F]"' input.txt

The following works as expected:

perl -lne '@ar = split / /; print "@ar[3..$#ar]"' input.txt

Why my autosplit does not work and how to fix it?

Perl 5.8.8 on RHEL 5.9.

like image 643
Philippe A. Avatar asked Feb 14 '23 15:02

Philippe A.


1 Answers

Workarounds to the "you can't put literal whitespace in the pattern" restriction:

perl -F\\x{20} ...
perl -F\\040   ...
like image 97
mob Avatar answered Mar 03 '23 08:03

mob