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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:49:13+00:00 2026-06-17T04:49:13+00:00

I have a large file which contains tables of different tab separated data. The

  • 0

I have a large file which contains tables of different tab separated data. The different tables are separated by a blank line.

I have the line number of the start of a particular table and I need to retrieve the whole table.

How can I use grep (or something similar) to get the line number of the next blank line after a specific line number?

  • 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-17T04:49:14+00:00Added an answer on June 17, 2026 at 4:49 am

    Use sed for this, this should do the trick:

    sed -n '1,/^\s*$/p' file
    

    Just replace the first number before the comma, in this case 1 with the line number, demo to print each table from a given line number:

    $ cat file
    one
    two
    three
    
    five
    six
    seven
    
    nine
    ten
    eleven
    
    $ sed -n '1,/^\s*$/p' file
    one
    two
    three
    
    $ sed -n '5,/^\s*$/p' file
    five
    six
    seven
    
    $ sed -n '9,/^\s*$/p' file
    nine
    ten
    eleven
    

    Using the -n option to turn of default printing of every line and the p flag sed prints from the line number to the first line that matches the regexp where:

    ^     # Matches the start of the line
    \s*   # Matches zero or more whitespace characters
    $     # Matches the end of the line
    

    Using the format sed -n 'A,Bp' where A and B can be either lines numbers or regular expression you can print subsections of files easily.

    To print just the line number of the next blank line with sed do:

    $ sed -n '1,/^\s*$/{=}' file | tail -1
    4
    
    $ sed -n '5,/^\s*$/{=}' file | tail -1
    8
    
    $ sed -n '9,/^\s*$/{=}' file | tail -1
    12
    

    Or just printing where all the blanks lines are

    $ sed -n '/^\s*$/{=}' file
    4
    8
    12
    

    Getting the next blank line number with awk doesn’t require using tail:

    $ awk 'NR>=1 && /^\s*$/{print NR;exit}' file
    4
    
    $ awk 'NR>=5 && /^\s*$/{print NR;exit}' file
    8
    
    $ awk 'NR>=9 && /^\s*$/{print NR;exit}' file
    12
    
    $ awk '/^\s*$/{print NR}' file
    4
    8
    12
    

    If it makes it clearer for you, you can pass a variable in with awk using -v

    $ awk -v start=1 'NR>=start && /^\s*$/{print NR;exit}' file
    4
    
    $ awk -v start=5 'NR>=start && /^\s*$/{print NR;exit}' file
    8
    
    $ awk -v start=9 'NR>=start && /^\s*$/{print NR;exit}' file
    12
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large file which contains 400000 lines, each line contains many number
I have a large raw data file (up to 1GB) which contains raw samples
I have a large txt file, which contains blocks of data as follows: AB
I have a large file which contains lots of data, and I'd like to
I have a very large text file which contains data similar to the following:
I have a very large text file which contains data similar to the following:
I have a large XML file which in the middle contains the following: <ArticleName>Article
I have a very large XML file which has like 40000 data, and when
I have a highly formatted file with large amount of data which I used
I have a large file where each line contains a substring such as ABC123.

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.