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.
Workarounds to the "you can't put literal whitespace in the pattern" restriction:
perl -F\\x{20} ...
perl -F\\040 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With