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 8043857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:02:57+00:00 2026-06-05T05:02:57+00:00

I am trying to extract column1 based on the values of column2. I would

  • 0

I am trying to extract column1 based on the values of column2. I would like to print the values of column1 only if column2 is ≤30 and greater than 5.

I also need to print the total number of the values of column1 based on the output. How can I do this with awk from multiple text files?

The sample of text file is shown below.

col1   col2  

aa     25
bb     4
cc     6
dd     23
aa     30

The output would be

aa
cc
dd
aa

Total number of aa is 2
Total number of cc is 1
Total number of dd is 1
  • 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-05T05:02:59+00:00Added an answer on June 5, 2026 at 5:02 am

    Something like this to get you started:

    { if ($2 <= 30 && $2 > 5) {
        print $1
        tot[$1] += 1 }
    }
    END {
    
      for (i in tot) {
        print "Total number of", i, "is", tot[i]
      }
    }
    

    Output:

    $ awk -f i.awk input
    aa
    cc
    dd
    aa
    Total number of aa is 2
    Total number of cc is 1
    Total number of dd is 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract not just the browser and its version number but also
I am trying to extract a table of values from an excel (2003) spreadsheet
Trying to extract strings that are wrapped in double brackets. For example [[this is
Trying to extract files to a given folder ignoring the path in the zipfile
Im trying to extract part of a line with perl use strict; use warnings;
I am trying to extract all the <input > tags out of a <form>
i'm trying to extract the content of an special div-tag(defined by his classname) out
I'm trying to extract about 72000 SInt32s from the iPhone, but not sure what
so i am trying to extract the email of my website using ruby mechanize
I'm trying to extract the parameter with which an app was called by using

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.