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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:33:51+00:00 2026-06-11T16:33:51+00:00

I am new to AWK. I have a large text file (>3GB). Like to

  • 0

I am new to AWK.

I have a large text file (>3GB). Like to use AWK line command to extract/print selected lines (line #62, #152 and 153) in that order and it iterates every 217 lines till end of record in file.

Tried to search and learn from the net. Tried the below and it does not seem working,

awk '{(for (i=62; i<=NR; i=i+217)||for (i=62; i<=NR; i=i+217)||for (i=62; i<=NR; i=i+217)); print}' file.txt

and

count=62||152||153
awk '{if (++count%217==0) print;}' file.txt

Could you assist to give me some pointers or lead me to any web which might be of help.

I am using this http://www.catonmat.net/blog/wp-content/uploads/2008/09/awk1line.txt to learn.

rgds
Saravanan K

Update #1 – 21 Sept 2012 – 10.40pm

Tried

awk 'NR == 62 || NR == 152 || NR == 153 || NR % 217 == 0 {print $0;}' file.txt

Able to print line #62, #152 and #153 but not all the following iterations e.g #(62+217), #(152+217) and #(153+217) and so on.

Tried the below too, but it is not working well.

awk '(NR == 62 || NR == 152 || NR == 153) && (((NR-62) % 217==0) || ((NR-152) % 217 ==0)|| ((NR-153) % 217==0)) {print $0;}' file.txt

Update #2 – 21 Sept 2012 – 10.55pm — CLOSED

I tried rmunoz idea with some tweaking. It worked like a magic. Thanks for rmunoz, with this I close this topic

awk '(NR - 62) % 217 == 0 || (NR - 152) % 217 == 0 || (NR - 153) % 217 ==0 {print $0;}' file.txt
  • 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-11T16:33:52+00:00Added an answer on June 11, 2026 at 4:33 pm

    You can use patterns in AWK this way:

     awk 'NR == 62 || NR == 152 || NR == 153 || NR % (62+217) == 0 || NR % (152+217) == 0 || NR % (153+217) == 0 {print $0;}' test.txt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a command line like this: awk '$9 < 0.1' s_all_frq.txt | wc
I have a text source (a log file), which gets new lines appended to
I have a file delimited by space. I need to write an awk command
I have a comma delimited file. The lines look like this... 1,2,3,4,5 6,7,8 9,10
I have some lines stored in a text file called bashrc_snippet . I would
I have an input file something like this: some line some other line another
I'm stil pretty new to regular expression and just started learning to use awk.
I have output with this format: /ignore-this/^/../I/want/this@ignore-this I am trying to use an awk
I have a group of files (of varying line number) that always finish like
I have a ever growing csv file that looks like: 143100, 2012-05-21 09:52:54.165852 125820,

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.