Sort command help

Posted on 2012-08-30
Last Modified: 2012-10-30

I have a file with around 200K records. I'm trying to get the number of occurances of each word with the following command:

tr ' ' '\n' |sort |uniq -c

This command is not sorting correctly...

I'm also using the following command to delete words from the main file which occur less than 100 times which is also not producing correct results.

perl -ne 's/(\S+)/$s{$1}/g,print,next if !@ARGV; ++$s{$_} for split; if( eof ){ $s{$_}=$s{$_}>=100&&$_ for keys %s}' file file >newfile

Please help with usage.

Question by:faithless1
    LVL 11

    Accepted Solution

    Hi FL1,

    > tr ' ' '\n' |sort |uniq -c
    > This command is not sorting correctly...

    1. Where are you specifying your input filename?  Please show us how you include the input filename in the (above) command.
    2. How do you know it's not sorting correctly?  Please give us a sample of the output and tell us what's wrong with it.

    LVL 84

    Expert Comment

    In what way does the result differ from the correct result?
    LVL 11

    Expert Comment

    Having just collected 500 points for asking a few questions, I think I must be getting good at this game.
    A pleasure doing business, FL1

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now