Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Delimited File Analysis One-Liner?

by temporal (Pilgrim)
on May 02, 2012 at 15:21 UTC ( #968468=note: print w/ replies, xml ) Need Help??


in reply to Re: Delimited File Analysis One-Liner?
in thread Delimited File Analysis One-Liner?

Thanks for the tip, BrowserUk. Always fun to learn a new trick.

I've generalized your code to match any column, where i is the column:

perl -F, -anE '$m<($x=length $F[i]) and $m=$x}{say $m' file.csv

I'd still use yours if I'm only looking in the first column. I wonder if there's a way to continue on that same idea (using index) and count delimiters out to a particular column and then save the distance between the most recent delimiters. Probably wouldn't be a one-liner at that point.

Also, curious about your use of $1. Is it a shell variable? Executing your command as written (in bash) doesn't give me any output, I have to switch the single and double quotes. Then I have to use a different variable, Perl won't let me assign to $1.

Strange things are afoot at the Circle-K.


Comment on Re^2: Delimited File Analysis One-Liner?
Download Code
Re^3: Delimited File Analysis One-Liner?
by BrowserUk (Pope) on May 02, 2012 at 16:19 UTC
    I wonder if there's a way to continue on that same idea (using index) and count delimiters out to a particular column

    No. Beyond the first column, -aF, is about as efficient as it gets.

    Also, curious about your use of $1.

    You need to get a better font! It isn't $1, (one) but rather $l (for length) and $m (for max).

    With any reasonable font they should be distinct, but I see it was a bad chioce for posting here.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      lol! Well, that explains why I was scratching my head. *goes font hunting*

      Strange things are afoot at the Circle-K.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://968468]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-08-01 11:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (8 votes), past polls