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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:41:59+00:00 2026-06-12T09:41:59+00:00

I have a simple question, which is almost too simple to find on this

  • 0

I have a simple question, which is almost too simple to find on this forum or on awk learning sites.

I have some awk code that matches a line beginning with a number, and prints the 6th column of that line:

/^[1-9]/ {   
print $6 
}

How do I tell it to print only the first 50 rows of the column from the match?


ADDITIONAL QUESTION

I tried used my own version of the answers below and I got it to print 50 lines. However, now I am trying to choose which 50 lines I print. I do this by skipping a line that starts with a number and contains the word ‘residue’. Then I skip 5 lines that start with a number and contain a ‘w’. This method is working as if I am only skipping the line with residue and prints from the first line starting with a number after that. Do you know why my ‘w’s are not being considered.

#!/usr/bin/awk -f

BEGIN {
    line  = 0;
    skipW = 0;
}


# Ignore all lines beginning with a number until I find one I'm interested in.
/^[0-9]+ residue/ { next }

# Ignore the first five lines beginning with a number followed by a 'w'.
/^[0-9]+ w/ { 
    skipW += 1;
    if (skipW <= 5) next
}

# For all other lines beginning with a number, perform the following.  If we are
# "printing", increment the line count.  When we've printed 50 lines turn off
# printing from that point on.
/^[0-9]+/ { 
    ++line
    if ((line > 0) && (line <= 50)) print $6
}
  • 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-12T09:42:00+00:00Added an answer on June 12, 2026 at 9:42 am
    awk '/^[1-9]/ { if (num_printed++ < 50) print $6 }'
    

    This increments num_printed each time a match is found and prints out the first 50 such lines, regardless of where the lines are in the files in the input.

    This reads through all the input. If an early exit is OK, then you can use:

    awk '/^[1-9]/ { print $6; if (++num_printed == 50) exit }'
    

    Note the switch from post-increment to pre-increment.

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

Sidebar

Related Questions

i have this simple question please. I have this part of code which sets
This is a simple question: I know and have heard from almost everyone that
I have a very simple question for which I can't seem to find an
Simple question which I can't seem to find an answer of: I have two
A fairly simple question for which I have a guess, but I can't find
The question is simple. I have a string that contains multiple elements which are
I have a pretty simple question which perhaps someone familiar with Server/Client design &
I have a question which I am sure is simple but I have slight
A simple question. I have an ASP.NET web application which contains several assemblies and
simple question... Given I have an ASP.NET site, which uses a [custom] RoleProvider, Is

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.