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

  • SEARCH
  • Home
  • 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 8772425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:01:41+00:00 2026-06-13T18:01:41+00:00

The input is like this: CNNCC NCNCN NNNCC CCNNN CCCCN The output should be

  • 0

The input is like this:

CNNCC
NCNCN
NNNCC
CCNNN
CCCCN

The output should be like this:

CNNCC
CCCCN

which means, if there’re more than 3 occurences of N, that line would be filtered out, otherwise it’s kept. (In my work, I need to filter out 100000 lines with more than 500 N so performance might be important)

I know how to filter by consecutive N in awk, but I don’t know how to calculate inconsecutive ones..

Does anyone have ideas about this? Solutions in shell is also ok.

Among all the answers, I think this one might be the simpest:

awk -FN 'NF<=3'
  • 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-13T18:01:42+00:00Added an answer on June 13, 2026 at 6:01 pm
    awk -FN -vcount=3 'NF<=count'
    

    or, for older awk which does not support the -v option,

    awk -FN 'NF<=count' count=3
    

    The command uses the target char as the field separator and the maximum allowed occurence as count. By comparing the resulting number of fields against count we can selectively print lines that meet our criteria.

    The intention of the statement is not immediately obvious and therefore less readable. It does however has the advantage of having the char and count parametrised and can therefore be easily reused for different settings.

    Admittedly, this would not be very efficient for large numbers of count. Setting the maximum number of fields to count+1 would overcome this performance issue, unfortunately the -mf option is ignored by gawk.

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

Sidebar

Related Questions

I have an input like this test1.test2.part01 which I want to strip away to
i have to make a program which can accept input like this: 2012-01-20 10:50:52
I have a program which provides a command line input like this: python2.6 prog.py
I have an input like this RX Only : Gi1/0/15,Gi1/0/20,Gi1/0/17 I want to capture
I have some input like this: aaaaa bbb \n cccccc\n ddddd \neeee And I
i have a input like this $desc = &lt;p&gt;\r\n test job description!&lt;/p&gt; i have
Is it possible for python to accept input like this: Folder name: Download But
I want to send the post data from an input like this: <input type=file
I have a Login page that captures User input like this. MD5calc ss =
We can initialize a container deque by using standard input like this: deque<int> c((istream_iterator<int>(cin)),(istream_iterator<int>()));

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.