willa has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone offer a command line bit of perl to take a file of columns, and give you only certain columns, but one of them is quoted with spaces? For example:
xxxxxx "xxx xxx" xxxx xxxxx xxxx xxxx xxxx
Counting the quoted column as one column, I want columns 1,2,3,5,6 and 7. Thanks!

Replies are listed 'Best First'.
Re: Easy one-liner
by pg (Canon) on Oct 20, 2004 at 10:16 UTC

    the other way is to use Text::ParseWords

    use Text::ParseWords; $_ ='1111 "222 222" 333 4444 55 666 77777'; print join(",", (quotewords('\s+', 0, $_))[0,1,2,4,5,6]);
    Update:

    As Corion suggested, here is the link toText::ParseWords

Re: Easy one-liner
by pg (Canon) on Oct 20, 2004 at 09:59 UTC
    $_ ='1111 "222 222" 333 4444 55 666 77777'; print join(",", (/"?((?<!")\S+(?<!")|[^"]+)"?\s*/g)[0,1,2,4,5,6]);

    This gives you:

    1111,222 222,333,55,666,77777