Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:57:48+00:00 2026-06-02T00:57:48+00:00

Is there an inbuilt command to do this or has anyone had any luck

  • 0

Is there an inbuilt command to do this or has anyone had any luck with a script that does it?

I am looking to get counts of how many records (as defined by a specific EOL such as “^%!”) had how many occurrences of a specfic character. (sorted descending by the number of occurrences)

For example, with this sample file:

jdk,|ljn^%!dk,|sn,|fgc^%!
ydfsvuyx^%!67ds5,|bvujhy,|s6d75
djh,|sudh^%!nhjf,|^%!fdiu^%!

Suggested input: delimiter EOL and filename as arguments.

bash/perl some_script_name ",|" "^%!" samplefile

Desired output:

occs    count
3        1
2        1
1        2
0        2

This is because the 1st record had one delimiter, 2nd record had 2, 3rd record had 0, 4th record had 3, 5th record had 1, 6th record had 0.

Bonus pts if you can make the delimiter and EOL argument accept hex input (ie 2C7C) or normal character input (ie ,|) .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:57:49+00:00Added an answer on June 2, 2026 at 12:57 am

    This is what perl lives for:

    #!perl -w
    use 5.12.0;
    
    my ($delim, $eol, $file) = @ARGV;
    
    open my $fh, "<$file" or die "error opening $file $!";
    $/ = $eol; # input record separator
    
    my %counts;
    while (<$fh>) {
        my $matches = () = $_ =~ /(\Q$delim\E)/g; # "goatse" operator
        $counts{$matches}++;
    }
    
    say "occs\tcount";
    foreach my $num (reverse sort keys %counts) {
        say "$num\t$counts{$num}";
    }
    

    (if you haven’t got 5.12, remove the “use 5.12” line and replace the say with print)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an inbuilt command to do this or has anyone had any luck
Hi does anyone know if there are any inbuilt classes for resolving a bound
Are there any inbuilt controls / APIs that will automatically pick up an email
Is there any inbuilt function in cpp that can give me the length of
Newbie question here, is there any inbuilt PHP tag that can be used to
Just want to know from experts that is there any inbuilt security for SQL
Is there an inbuilt function that removes the Kth row and column of a
Is there any way to find the key that corresponds to a given item
Is there an inbuilt ASP.Net or MVC3 function that generates a valid CSS class
Is there an inbuilt function in postgres that allows the user to set the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.