Grepping string, but include all non-blank lines following each grep match2019 Community Moderator ElectionHow can I grep a directory based on the contents of two successive lines?grep: Find all lines that contain Japanese kanjisBlank lines when executing “grep | xargs” in a “find -exec”How to use grep/awk/unix to match all lines from one file in another file, even if they are duplicatesRemove all the lines before the first line that contains a match?grep match all occurrences of multiple regular expressionsCompare two files and retrieve corresponding resultsregex and grep: match all letters in a listHow to search for a match, then a non-match on that line, but include context lines for matched line?How to `grep -v` and also exclude 'n' lines after the match?

"Oh no!" in Latin

Sigmoid with a slope but no asymptotes?

How to get directions in deep space?

Air travel with refrigerated insulin

Can I say "fingers" when referring to toes?

How would a solely written language work mechanically

Make a border of symbols in Gimp

Do I have to know the General Relativity theory to understand the concept of inertial frame?

El Dorado Word Puzzle II: Videogame Edition

What does the word 'upstream' mean in the context?

How do I prevent inappropriate ads from appearing in my game?

Giving feedback to someone without sounding prejudiced

Quoting Keynes in a lecture

What should be the ideal length of sentences in a blog post for ease of reading?

Why can't the Brexit deadlock in the UK parliament be solved with a plurality vote?

Storage of electrolytic capacitors - how long?

Why didn't Voldemort know what Grindelwald looked like?

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?

When and why was runway 07/25 at Kai Tak removed?

How do I fix the group tension caused by my character stealing and possibly killing without provocation?

What is the meaning of "You've never met a graph you didn't like?"

Where can I find the genesis file for mainnet?

Proving an identity involving cross products and coplanar vectors

Confusion over Hunter with Crossbow Expert and Giant Killer



Grepping string, but include all non-blank lines following each grep match



2019 Community Moderator ElectionHow can I grep a directory based on the contents of two successive lines?grep: Find all lines that contain Japanese kanjisBlank lines when executing “grep | xargs” in a “find -exec”How to use grep/awk/unix to match all lines from one file in another file, even if they are duplicatesRemove all the lines before the first line that contains a match?grep match all occurrences of multiple regular expressionsCompare two files and retrieve corresponding resultsregex and grep: match all letters in a listHow to search for a match, then a non-match on that line, but include context lines for matched line?How to `grep -v` and also exclude 'n' lines after the match?










5















Consider the following toy example:



this is a line 
this line contains FOO
this line is not blank

This line also contains FOO

Some random text

This line contains FOO too
Not blank
Also not blank

More random text
FOO!
Yet more random text
FOO!


So, I want the results of a grep for FOO, but with the extra wrinkle that lines following the matching lines should be included, as long as they are not blank, and they do not themselves contain FOO. So the matches would look as follows, with the different matches separated:



MATCH 1



this line contains FOO 
this line is not blank


MATCH 2



This line also contains FOO


MATCH 3



This line contains FOO too 
Not blank
Also not blank


MATCH 4



FOO!
Yet more random text


MATCH 5



FOO!


Bonus points (metaphorically speaking) for a simple single line script that can be run on the command line.



ADDENDUM: Adding a running count of the match number would be quite handy, if it is not too hard.










share|improve this question



















  • 1





    do you want all the Matches in one output or you want them to be ran separately ?

    – Vivek Kanadiya
    1 hour ago











  • I guess one output is fine, as long as they are clearly separated, say by a blank line.

    – Faheem Mitha
    1 hour ago











  • might not possible in one output but I can try to see in each separate output!

    – Vivek Kanadiya
    1 hour ago











  • For matches 4 & 5, the simple logic could say "I've matched (the 4th) "FOO", so I should continue printing in this matching block until I see a blank line, and so the final "FOO" is included in this block", but i see you've separated it -- because it's a separate "FOO" match. Do you require the 5th "FOO" to be printed separately?

    – Jeff Schaller
    1 hour ago











  • @JeffSchaller Yes, please separate different FOO matches.

    – Faheem Mitha
    1 hour ago















5















Consider the following toy example:



this is a line 
this line contains FOO
this line is not blank

This line also contains FOO

Some random text

This line contains FOO too
Not blank
Also not blank

More random text
FOO!
Yet more random text
FOO!


So, I want the results of a grep for FOO, but with the extra wrinkle that lines following the matching lines should be included, as long as they are not blank, and they do not themselves contain FOO. So the matches would look as follows, with the different matches separated:



MATCH 1



this line contains FOO 
this line is not blank


MATCH 2



This line also contains FOO


MATCH 3



This line contains FOO too 
Not blank
Also not blank


MATCH 4



FOO!
Yet more random text


MATCH 5



FOO!


Bonus points (metaphorically speaking) for a simple single line script that can be run on the command line.



ADDENDUM: Adding a running count of the match number would be quite handy, if it is not too hard.










share|improve this question



















  • 1





    do you want all the Matches in one output or you want them to be ran separately ?

    – Vivek Kanadiya
    1 hour ago











  • I guess one output is fine, as long as they are clearly separated, say by a blank line.

    – Faheem Mitha
    1 hour ago











  • might not possible in one output but I can try to see in each separate output!

    – Vivek Kanadiya
    1 hour ago











  • For matches 4 & 5, the simple logic could say "I've matched (the 4th) "FOO", so I should continue printing in this matching block until I see a blank line, and so the final "FOO" is included in this block", but i see you've separated it -- because it's a separate "FOO" match. Do you require the 5th "FOO" to be printed separately?

    – Jeff Schaller
    1 hour ago











  • @JeffSchaller Yes, please separate different FOO matches.

    – Faheem Mitha
    1 hour ago













5












5








5








Consider the following toy example:



this is a line 
this line contains FOO
this line is not blank

This line also contains FOO

Some random text

This line contains FOO too
Not blank
Also not blank

More random text
FOO!
Yet more random text
FOO!


So, I want the results of a grep for FOO, but with the extra wrinkle that lines following the matching lines should be included, as long as they are not blank, and they do not themselves contain FOO. So the matches would look as follows, with the different matches separated:



MATCH 1



this line contains FOO 
this line is not blank


MATCH 2



This line also contains FOO


MATCH 3



This line contains FOO too 
Not blank
Also not blank


MATCH 4



FOO!
Yet more random text


MATCH 5



FOO!


Bonus points (metaphorically speaking) for a simple single line script that can be run on the command line.



ADDENDUM: Adding a running count of the match number would be quite handy, if it is not too hard.










share|improve this question
















Consider the following toy example:



this is a line 
this line contains FOO
this line is not blank

This line also contains FOO

Some random text

This line contains FOO too
Not blank
Also not blank

More random text
FOO!
Yet more random text
FOO!


So, I want the results of a grep for FOO, but with the extra wrinkle that lines following the matching lines should be included, as long as they are not blank, and they do not themselves contain FOO. So the matches would look as follows, with the different matches separated:



MATCH 1



this line contains FOO 
this line is not blank


MATCH 2



This line also contains FOO


MATCH 3



This line contains FOO too 
Not blank
Also not blank


MATCH 4



FOO!
Yet more random text


MATCH 5



FOO!


Bonus points (metaphorically speaking) for a simple single line script that can be run on the command line.



ADDENDUM: Adding a running count of the match number would be quite handy, if it is not too hard.







text-processing grep






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago







Faheem Mitha

















asked 1 hour ago









Faheem MithaFaheem Mitha

23.1k1884137




23.1k1884137







  • 1





    do you want all the Matches in one output or you want them to be ran separately ?

    – Vivek Kanadiya
    1 hour ago











  • I guess one output is fine, as long as they are clearly separated, say by a blank line.

    – Faheem Mitha
    1 hour ago











  • might not possible in one output but I can try to see in each separate output!

    – Vivek Kanadiya
    1 hour ago











  • For matches 4 & 5, the simple logic could say "I've matched (the 4th) "FOO", so I should continue printing in this matching block until I see a blank line, and so the final "FOO" is included in this block", but i see you've separated it -- because it's a separate "FOO" match. Do you require the 5th "FOO" to be printed separately?

    – Jeff Schaller
    1 hour ago











  • @JeffSchaller Yes, please separate different FOO matches.

    – Faheem Mitha
    1 hour ago












  • 1





    do you want all the Matches in one output or you want them to be ran separately ?

    – Vivek Kanadiya
    1 hour ago











  • I guess one output is fine, as long as they are clearly separated, say by a blank line.

    – Faheem Mitha
    1 hour ago











  • might not possible in one output but I can try to see in each separate output!

    – Vivek Kanadiya
    1 hour ago











  • For matches 4 & 5, the simple logic could say "I've matched (the 4th) "FOO", so I should continue printing in this matching block until I see a blank line, and so the final "FOO" is included in this block", but i see you've separated it -- because it's a separate "FOO" match. Do you require the 5th "FOO" to be printed separately?

    – Jeff Schaller
    1 hour ago











  • @JeffSchaller Yes, please separate different FOO matches.

    – Faheem Mitha
    1 hour ago







1




1





do you want all the Matches in one output or you want them to be ran separately ?

– Vivek Kanadiya
1 hour ago





do you want all the Matches in one output or you want them to be ran separately ?

– Vivek Kanadiya
1 hour ago













I guess one output is fine, as long as they are clearly separated, say by a blank line.

– Faheem Mitha
1 hour ago





I guess one output is fine, as long as they are clearly separated, say by a blank line.

– Faheem Mitha
1 hour ago













might not possible in one output but I can try to see in each separate output!

– Vivek Kanadiya
1 hour ago





might not possible in one output but I can try to see in each separate output!

– Vivek Kanadiya
1 hour ago













For matches 4 & 5, the simple logic could say "I've matched (the 4th) "FOO", so I should continue printing in this matching block until I see a blank line, and so the final "FOO" is included in this block", but i see you've separated it -- because it's a separate "FOO" match. Do you require the 5th "FOO" to be printed separately?

– Jeff Schaller
1 hour ago





For matches 4 & 5, the simple logic could say "I've matched (the 4th) "FOO", so I should continue printing in this matching block until I see a blank line, and so the final "FOO" is included in this block", but i see you've separated it -- because it's a separate "FOO" match. Do you require the 5th "FOO" to be printed separately?

– Jeff Schaller
1 hour ago













@JeffSchaller Yes, please separate different FOO matches.

– Faheem Mitha
1 hour ago





@JeffSchaller Yes, please separate different FOO matches.

– Faheem Mitha
1 hour ago










5 Answers
5






active

oldest

votes


















4














Using awk rather than grep:



awk '/FOO/ if (matching) printf("n"); matching = 1 
/^$/ if (matching) printf("n"); matching = 0
matching' file


A version that enumerates the matches:



awk 'function flush_print_maybe() 
if (matching) printf("Match %dn%snn", ++n, buf)
buf = ""

/FOO/ flush_print_maybe(); matching = 1
/^$/ flush_print_maybe(); matching = 0
matching buf = (buf == "" ? $0 : buf ORS $0)
END flush_print_maybe() ' file


Both awk programs uses a very simple "state machine" to determine if it's currently matching or not matching. A match of the pattern FOO will cause it to enter the matching state, and a match of the pattern ^$ (an empty line) will cause it to enter the non-matching state.



Output of empty lines between matching sets of data happens at state transitions from matching (either into matching or into non-matching).



The first program prints any line when in the matching state.



The second program collects lines in a buf variable when in a matching state. It flushes (empties) this after possibly printing it (depending on the state), together with a Match N label at state transitions (when the first program would output an empty line).



Output of this last program on the sample data:



Match 1
this line contains FOO
this line is not blank

Match 2
This line also contains FOO

Match 3
This line contains FOO too
Not blank
Also not blank

Match 4
FOO!
Yet more random text

Match 5
FOO!





share|improve this answer
































    3














    I don’t think this is doable with grep, but it is with AWK:



    #! /usr/bin/awk -f

    /FOO/
    matched = 1
    if (notfirst) print ""
    notfirst = 1


    /^$/
    matched = 0


    matched





    share|improve this answer

























    • at the start of the output, period, right?

      – ilkkachu
      1 hour ago






    • 1





      At the start of the output, yes; I’ve fixed that.

      – Stephen Kitt
      57 mins ago


















    2














    sed -ne '/FOO/x;P;x;/FOO/,/^$/p' testfile


    Each block of non-empty lines in the output is a single chunk of matched data from the input. The number of newlines varies.



    This



    1. suppresses output (-n); then

    2. prints a blank line before every occurrence of "FOO" (/FOO/x;P;x - uses the empty hold space);

    3. selects ranges of lines starting from ones containing FOO (/FOO/) and ending on empty lines (/^$/); and finally

    4. prints those lines (p).


    this line contains FOO
    this line is not blank


    This line also contains FOO


    This line contains FOO too
    Not blank
    Also not blank


    FOO!
    Yet more random text

    FOO!





    share|improve this answer
































      0














      I've included a pcregrep solution and a python solution.



      Multiline Grep Solution



      If you have pcregrep installed, you could use a multiline pattern, such as ^.*FOO.*$n?(^.*S.*$n?)*, e.g.:



      pcregrep -M '^.*FOO.*$n?(^.*S.*$n?)*' test.txt


      The subexpression ^.*FOO.*$n? will match any line containing the string FOO and the subexpression (^.*S.*$n?)* will match any number of subsequent lines that containing a non-whitespace character.



      Python Solution



      Here is a Python script that should do what you want:



      #!/usr/bin/env python3
      # -*- encoding: utf8 -*-
      """grep_follow.py

      Search a text file for a pattern,
      and output that pattern and the
      non-empty lines which immediately follow it.
      """

      import re
      import sys

      # Get the search pattern and the input file as command-line arguments
      pattern = sys.argv[1]
      input_file = sys.argv[2]

      # Set a flag to determine whether or not to output the current line
      print_flag = False

      with open(input_file, "r") as _input_file:

      # Iterate over the lines of the input file
      for line in _input_file:

      # Remove trailing whitespace
      line = line.rstrip()

      # If the line is empty, stop producing output
      if not line.strip():
      print_flag = False

      # If the line matches the search pattern, start producing output
      elif re.search(pattern, line):
      print_flag = True

      # If the print flag is set then output the line
      if print_flag:
      print(line)


      You would run it like this:



      $ python grep_follow.py FOO test.txt


      this line contains FOO
      this line is not blank
      This line also contains FOO
      This line contains FOO too
      Not blank
      Also not blank
      FOO!
      Yet more random text
      FOO!





      share|improve this answer
































        -4














        Here's what I can get the output that is desired!



        Match 1:



        grep -iE "FOO|blank" toy.txt | head -2



        Match 2:



        grep -iE "FOO|blank" file.txt | grep also



        Match 3:



        grep -iE "FOO|blank" file.txt | tail -n 5 | head -n 3



        Match 4:



        grep -iE "FOO|text" file.txt | tail -n 2



        Match 5:



        grep -iE "FOO|text" file.txt | tail -n 1






        share|improve this answer










        New contributor




        Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















        • This assumes knowledge of the contents of the file.

          – Kusalananda
          1 hour ago











        • yes this is based on knowledge of file

          – Vivek Kanadiya
          1 hour ago






        • 1





          @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

          – ilkkachu
          1 hour ago










        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507517%2fgrepping-string-but-include-all-non-blank-lines-following-each-grep-match%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        4














        Using awk rather than grep:



        awk '/FOO/ if (matching) printf("n"); matching = 1 
        /^$/ if (matching) printf("n"); matching = 0
        matching' file


        A version that enumerates the matches:



        awk 'function flush_print_maybe() 
        if (matching) printf("Match %dn%snn", ++n, buf)
        buf = ""

        /FOO/ flush_print_maybe(); matching = 1
        /^$/ flush_print_maybe(); matching = 0
        matching buf = (buf == "" ? $0 : buf ORS $0)
        END flush_print_maybe() ' file


        Both awk programs uses a very simple "state machine" to determine if it's currently matching or not matching. A match of the pattern FOO will cause it to enter the matching state, and a match of the pattern ^$ (an empty line) will cause it to enter the non-matching state.



        Output of empty lines between matching sets of data happens at state transitions from matching (either into matching or into non-matching).



        The first program prints any line when in the matching state.



        The second program collects lines in a buf variable when in a matching state. It flushes (empties) this after possibly printing it (depending on the state), together with a Match N label at state transitions (when the first program would output an empty line).



        Output of this last program on the sample data:



        Match 1
        this line contains FOO
        this line is not blank

        Match 2
        This line also contains FOO

        Match 3
        This line contains FOO too
        Not blank
        Also not blank

        Match 4
        FOO!
        Yet more random text

        Match 5
        FOO!





        share|improve this answer





























          4














          Using awk rather than grep:



          awk '/FOO/ if (matching) printf("n"); matching = 1 
          /^$/ if (matching) printf("n"); matching = 0
          matching' file


          A version that enumerates the matches:



          awk 'function flush_print_maybe() 
          if (matching) printf("Match %dn%snn", ++n, buf)
          buf = ""

          /FOO/ flush_print_maybe(); matching = 1
          /^$/ flush_print_maybe(); matching = 0
          matching buf = (buf == "" ? $0 : buf ORS $0)
          END flush_print_maybe() ' file


          Both awk programs uses a very simple "state machine" to determine if it's currently matching or not matching. A match of the pattern FOO will cause it to enter the matching state, and a match of the pattern ^$ (an empty line) will cause it to enter the non-matching state.



          Output of empty lines between matching sets of data happens at state transitions from matching (either into matching or into non-matching).



          The first program prints any line when in the matching state.



          The second program collects lines in a buf variable when in a matching state. It flushes (empties) this after possibly printing it (depending on the state), together with a Match N label at state transitions (when the first program would output an empty line).



          Output of this last program on the sample data:



          Match 1
          this line contains FOO
          this line is not blank

          Match 2
          This line also contains FOO

          Match 3
          This line contains FOO too
          Not blank
          Also not blank

          Match 4
          FOO!
          Yet more random text

          Match 5
          FOO!





          share|improve this answer



























            4












            4








            4







            Using awk rather than grep:



            awk '/FOO/ if (matching) printf("n"); matching = 1 
            /^$/ if (matching) printf("n"); matching = 0
            matching' file


            A version that enumerates the matches:



            awk 'function flush_print_maybe() 
            if (matching) printf("Match %dn%snn", ++n, buf)
            buf = ""

            /FOO/ flush_print_maybe(); matching = 1
            /^$/ flush_print_maybe(); matching = 0
            matching buf = (buf == "" ? $0 : buf ORS $0)
            END flush_print_maybe() ' file


            Both awk programs uses a very simple "state machine" to determine if it's currently matching or not matching. A match of the pattern FOO will cause it to enter the matching state, and a match of the pattern ^$ (an empty line) will cause it to enter the non-matching state.



            Output of empty lines between matching sets of data happens at state transitions from matching (either into matching or into non-matching).



            The first program prints any line when in the matching state.



            The second program collects lines in a buf variable when in a matching state. It flushes (empties) this after possibly printing it (depending on the state), together with a Match N label at state transitions (when the first program would output an empty line).



            Output of this last program on the sample data:



            Match 1
            this line contains FOO
            this line is not blank

            Match 2
            This line also contains FOO

            Match 3
            This line contains FOO too
            Not blank
            Also not blank

            Match 4
            FOO!
            Yet more random text

            Match 5
            FOO!





            share|improve this answer















            Using awk rather than grep:



            awk '/FOO/ if (matching) printf("n"); matching = 1 
            /^$/ if (matching) printf("n"); matching = 0
            matching' file


            A version that enumerates the matches:



            awk 'function flush_print_maybe() 
            if (matching) printf("Match %dn%snn", ++n, buf)
            buf = ""

            /FOO/ flush_print_maybe(); matching = 1
            /^$/ flush_print_maybe(); matching = 0
            matching buf = (buf == "" ? $0 : buf ORS $0)
            END flush_print_maybe() ' file


            Both awk programs uses a very simple "state machine" to determine if it's currently matching or not matching. A match of the pattern FOO will cause it to enter the matching state, and a match of the pattern ^$ (an empty line) will cause it to enter the non-matching state.



            Output of empty lines between matching sets of data happens at state transitions from matching (either into matching or into non-matching).



            The first program prints any line when in the matching state.



            The second program collects lines in a buf variable when in a matching state. It flushes (empties) this after possibly printing it (depending on the state), together with a Match N label at state transitions (when the first program would output an empty line).



            Output of this last program on the sample data:



            Match 1
            this line contains FOO
            this line is not blank

            Match 2
            This line also contains FOO

            Match 3
            This line contains FOO too
            Not blank
            Also not blank

            Match 4
            FOO!
            Yet more random text

            Match 5
            FOO!






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 57 mins ago

























            answered 1 hour ago









            KusalanandaKusalananda

            136k17257426




            136k17257426























                3














                I don’t think this is doable with grep, but it is with AWK:



                #! /usr/bin/awk -f

                /FOO/
                matched = 1
                if (notfirst) print ""
                notfirst = 1


                /^$/
                matched = 0


                matched





                share|improve this answer

























                • at the start of the output, period, right?

                  – ilkkachu
                  1 hour ago






                • 1





                  At the start of the output, yes; I’ve fixed that.

                  – Stephen Kitt
                  57 mins ago















                3














                I don’t think this is doable with grep, but it is with AWK:



                #! /usr/bin/awk -f

                /FOO/
                matched = 1
                if (notfirst) print ""
                notfirst = 1


                /^$/
                matched = 0


                matched





                share|improve this answer

























                • at the start of the output, period, right?

                  – ilkkachu
                  1 hour ago






                • 1





                  At the start of the output, yes; I’ve fixed that.

                  – Stephen Kitt
                  57 mins ago













                3












                3








                3







                I don’t think this is doable with grep, but it is with AWK:



                #! /usr/bin/awk -f

                /FOO/
                matched = 1
                if (notfirst) print ""
                notfirst = 1


                /^$/
                matched = 0


                matched





                share|improve this answer















                I don’t think this is doable with grep, but it is with AWK:



                #! /usr/bin/awk -f

                /FOO/
                matched = 1
                if (notfirst) print ""
                notfirst = 1


                /^$/
                matched = 0


                matched






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 58 mins ago

























                answered 1 hour ago









                Stephen KittStephen Kitt

                177k24402479




                177k24402479












                • at the start of the output, period, right?

                  – ilkkachu
                  1 hour ago






                • 1





                  At the start of the output, yes; I’ve fixed that.

                  – Stephen Kitt
                  57 mins ago

















                • at the start of the output, period, right?

                  – ilkkachu
                  1 hour ago






                • 1





                  At the start of the output, yes; I’ve fixed that.

                  – Stephen Kitt
                  57 mins ago
















                at the start of the output, period, right?

                – ilkkachu
                1 hour ago





                at the start of the output, period, right?

                – ilkkachu
                1 hour ago




                1




                1





                At the start of the output, yes; I’ve fixed that.

                – Stephen Kitt
                57 mins ago





                At the start of the output, yes; I’ve fixed that.

                – Stephen Kitt
                57 mins ago











                2














                sed -ne '/FOO/x;P;x;/FOO/,/^$/p' testfile


                Each block of non-empty lines in the output is a single chunk of matched data from the input. The number of newlines varies.



                This



                1. suppresses output (-n); then

                2. prints a blank line before every occurrence of "FOO" (/FOO/x;P;x - uses the empty hold space);

                3. selects ranges of lines starting from ones containing FOO (/FOO/) and ending on empty lines (/^$/); and finally

                4. prints those lines (p).


                this line contains FOO
                this line is not blank


                This line also contains FOO


                This line contains FOO too
                Not blank
                Also not blank


                FOO!
                Yet more random text

                FOO!





                share|improve this answer





























                  2














                  sed -ne '/FOO/x;P;x;/FOO/,/^$/p' testfile


                  Each block of non-empty lines in the output is a single chunk of matched data from the input. The number of newlines varies.



                  This



                  1. suppresses output (-n); then

                  2. prints a blank line before every occurrence of "FOO" (/FOO/x;P;x - uses the empty hold space);

                  3. selects ranges of lines starting from ones containing FOO (/FOO/) and ending on empty lines (/^$/); and finally

                  4. prints those lines (p).


                  this line contains FOO
                  this line is not blank


                  This line also contains FOO


                  This line contains FOO too
                  Not blank
                  Also not blank


                  FOO!
                  Yet more random text

                  FOO!





                  share|improve this answer



























                    2












                    2








                    2







                    sed -ne '/FOO/x;P;x;/FOO/,/^$/p' testfile


                    Each block of non-empty lines in the output is a single chunk of matched data from the input. The number of newlines varies.



                    This



                    1. suppresses output (-n); then

                    2. prints a blank line before every occurrence of "FOO" (/FOO/x;P;x - uses the empty hold space);

                    3. selects ranges of lines starting from ones containing FOO (/FOO/) and ending on empty lines (/^$/); and finally

                    4. prints those lines (p).


                    this line contains FOO
                    this line is not blank


                    This line also contains FOO


                    This line contains FOO too
                    Not blank
                    Also not blank


                    FOO!
                    Yet more random text

                    FOO!





                    share|improve this answer















                    sed -ne '/FOO/x;P;x;/FOO/,/^$/p' testfile


                    Each block of non-empty lines in the output is a single chunk of matched data from the input. The number of newlines varies.



                    This



                    1. suppresses output (-n); then

                    2. prints a blank line before every occurrence of "FOO" (/FOO/x;P;x - uses the empty hold space);

                    3. selects ranges of lines starting from ones containing FOO (/FOO/) and ending on empty lines (/^$/); and finally

                    4. prints those lines (p).


                    this line contains FOO
                    this line is not blank


                    This line also contains FOO


                    This line contains FOO too
                    Not blank
                    Also not blank


                    FOO!
                    Yet more random text

                    FOO!






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 48 mins ago

























                    answered 1 hour ago









                    Michael HomerMichael Homer

                    49.9k8137175




                    49.9k8137175





















                        0














                        I've included a pcregrep solution and a python solution.



                        Multiline Grep Solution



                        If you have pcregrep installed, you could use a multiline pattern, such as ^.*FOO.*$n?(^.*S.*$n?)*, e.g.:



                        pcregrep -M '^.*FOO.*$n?(^.*S.*$n?)*' test.txt


                        The subexpression ^.*FOO.*$n? will match any line containing the string FOO and the subexpression (^.*S.*$n?)* will match any number of subsequent lines that containing a non-whitespace character.



                        Python Solution



                        Here is a Python script that should do what you want:



                        #!/usr/bin/env python3
                        # -*- encoding: utf8 -*-
                        """grep_follow.py

                        Search a text file for a pattern,
                        and output that pattern and the
                        non-empty lines which immediately follow it.
                        """

                        import re
                        import sys

                        # Get the search pattern and the input file as command-line arguments
                        pattern = sys.argv[1]
                        input_file = sys.argv[2]

                        # Set a flag to determine whether or not to output the current line
                        print_flag = False

                        with open(input_file, "r") as _input_file:

                        # Iterate over the lines of the input file
                        for line in _input_file:

                        # Remove trailing whitespace
                        line = line.rstrip()

                        # If the line is empty, stop producing output
                        if not line.strip():
                        print_flag = False

                        # If the line matches the search pattern, start producing output
                        elif re.search(pattern, line):
                        print_flag = True

                        # If the print flag is set then output the line
                        if print_flag:
                        print(line)


                        You would run it like this:



                        $ python grep_follow.py FOO test.txt


                        this line contains FOO
                        this line is not blank
                        This line also contains FOO
                        This line contains FOO too
                        Not blank
                        Also not blank
                        FOO!
                        Yet more random text
                        FOO!





                        share|improve this answer





























                          0














                          I've included a pcregrep solution and a python solution.



                          Multiline Grep Solution



                          If you have pcregrep installed, you could use a multiline pattern, such as ^.*FOO.*$n?(^.*S.*$n?)*, e.g.:



                          pcregrep -M '^.*FOO.*$n?(^.*S.*$n?)*' test.txt


                          The subexpression ^.*FOO.*$n? will match any line containing the string FOO and the subexpression (^.*S.*$n?)* will match any number of subsequent lines that containing a non-whitespace character.



                          Python Solution



                          Here is a Python script that should do what you want:



                          #!/usr/bin/env python3
                          # -*- encoding: utf8 -*-
                          """grep_follow.py

                          Search a text file for a pattern,
                          and output that pattern and the
                          non-empty lines which immediately follow it.
                          """

                          import re
                          import sys

                          # Get the search pattern and the input file as command-line arguments
                          pattern = sys.argv[1]
                          input_file = sys.argv[2]

                          # Set a flag to determine whether or not to output the current line
                          print_flag = False

                          with open(input_file, "r") as _input_file:

                          # Iterate over the lines of the input file
                          for line in _input_file:

                          # Remove trailing whitespace
                          line = line.rstrip()

                          # If the line is empty, stop producing output
                          if not line.strip():
                          print_flag = False

                          # If the line matches the search pattern, start producing output
                          elif re.search(pattern, line):
                          print_flag = True

                          # If the print flag is set then output the line
                          if print_flag:
                          print(line)


                          You would run it like this:



                          $ python grep_follow.py FOO test.txt


                          this line contains FOO
                          this line is not blank
                          This line also contains FOO
                          This line contains FOO too
                          Not blank
                          Also not blank
                          FOO!
                          Yet more random text
                          FOO!





                          share|improve this answer



























                            0












                            0








                            0







                            I've included a pcregrep solution and a python solution.



                            Multiline Grep Solution



                            If you have pcregrep installed, you could use a multiline pattern, such as ^.*FOO.*$n?(^.*S.*$n?)*, e.g.:



                            pcregrep -M '^.*FOO.*$n?(^.*S.*$n?)*' test.txt


                            The subexpression ^.*FOO.*$n? will match any line containing the string FOO and the subexpression (^.*S.*$n?)* will match any number of subsequent lines that containing a non-whitespace character.



                            Python Solution



                            Here is a Python script that should do what you want:



                            #!/usr/bin/env python3
                            # -*- encoding: utf8 -*-
                            """grep_follow.py

                            Search a text file for a pattern,
                            and output that pattern and the
                            non-empty lines which immediately follow it.
                            """

                            import re
                            import sys

                            # Get the search pattern and the input file as command-line arguments
                            pattern = sys.argv[1]
                            input_file = sys.argv[2]

                            # Set a flag to determine whether or not to output the current line
                            print_flag = False

                            with open(input_file, "r") as _input_file:

                            # Iterate over the lines of the input file
                            for line in _input_file:

                            # Remove trailing whitespace
                            line = line.rstrip()

                            # If the line is empty, stop producing output
                            if not line.strip():
                            print_flag = False

                            # If the line matches the search pattern, start producing output
                            elif re.search(pattern, line):
                            print_flag = True

                            # If the print flag is set then output the line
                            if print_flag:
                            print(line)


                            You would run it like this:



                            $ python grep_follow.py FOO test.txt


                            this line contains FOO
                            this line is not blank
                            This line also contains FOO
                            This line contains FOO too
                            Not blank
                            Also not blank
                            FOO!
                            Yet more random text
                            FOO!





                            share|improve this answer















                            I've included a pcregrep solution and a python solution.



                            Multiline Grep Solution



                            If you have pcregrep installed, you could use a multiline pattern, such as ^.*FOO.*$n?(^.*S.*$n?)*, e.g.:



                            pcregrep -M '^.*FOO.*$n?(^.*S.*$n?)*' test.txt


                            The subexpression ^.*FOO.*$n? will match any line containing the string FOO and the subexpression (^.*S.*$n?)* will match any number of subsequent lines that containing a non-whitespace character.



                            Python Solution



                            Here is a Python script that should do what you want:



                            #!/usr/bin/env python3
                            # -*- encoding: utf8 -*-
                            """grep_follow.py

                            Search a text file for a pattern,
                            and output that pattern and the
                            non-empty lines which immediately follow it.
                            """

                            import re
                            import sys

                            # Get the search pattern and the input file as command-line arguments
                            pattern = sys.argv[1]
                            input_file = sys.argv[2]

                            # Set a flag to determine whether or not to output the current line
                            print_flag = False

                            with open(input_file, "r") as _input_file:

                            # Iterate over the lines of the input file
                            for line in _input_file:

                            # Remove trailing whitespace
                            line = line.rstrip()

                            # If the line is empty, stop producing output
                            if not line.strip():
                            print_flag = False

                            # If the line matches the search pattern, start producing output
                            elif re.search(pattern, line):
                            print_flag = True

                            # If the print flag is set then output the line
                            if print_flag:
                            print(line)


                            You would run it like this:



                            $ python grep_follow.py FOO test.txt


                            this line contains FOO
                            this line is not blank
                            This line also contains FOO
                            This line contains FOO too
                            Not blank
                            Also not blank
                            FOO!
                            Yet more random text
                            FOO!






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited 1 hour ago

























                            answered 1 hour ago









                            igaligal

                            5,9311536




                            5,9311536





















                                -4














                                Here's what I can get the output that is desired!



                                Match 1:



                                grep -iE "FOO|blank" toy.txt | head -2



                                Match 2:



                                grep -iE "FOO|blank" file.txt | grep also



                                Match 3:



                                grep -iE "FOO|blank" file.txt | tail -n 5 | head -n 3



                                Match 4:



                                grep -iE "FOO|text" file.txt | tail -n 2



                                Match 5:



                                grep -iE "FOO|text" file.txt | tail -n 1






                                share|improve this answer










                                New contributor




                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.




















                                • This assumes knowledge of the contents of the file.

                                  – Kusalananda
                                  1 hour ago











                                • yes this is based on knowledge of file

                                  – Vivek Kanadiya
                                  1 hour ago






                                • 1





                                  @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

                                  – ilkkachu
                                  1 hour ago















                                -4














                                Here's what I can get the output that is desired!



                                Match 1:



                                grep -iE "FOO|blank" toy.txt | head -2



                                Match 2:



                                grep -iE "FOO|blank" file.txt | grep also



                                Match 3:



                                grep -iE "FOO|blank" file.txt | tail -n 5 | head -n 3



                                Match 4:



                                grep -iE "FOO|text" file.txt | tail -n 2



                                Match 5:



                                grep -iE "FOO|text" file.txt | tail -n 1






                                share|improve this answer










                                New contributor




                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.




















                                • This assumes knowledge of the contents of the file.

                                  – Kusalananda
                                  1 hour ago











                                • yes this is based on knowledge of file

                                  – Vivek Kanadiya
                                  1 hour ago






                                • 1





                                  @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

                                  – ilkkachu
                                  1 hour ago













                                -4












                                -4








                                -4







                                Here's what I can get the output that is desired!



                                Match 1:



                                grep -iE "FOO|blank" toy.txt | head -2



                                Match 2:



                                grep -iE "FOO|blank" file.txt | grep also



                                Match 3:



                                grep -iE "FOO|blank" file.txt | tail -n 5 | head -n 3



                                Match 4:



                                grep -iE "FOO|text" file.txt | tail -n 2



                                Match 5:



                                grep -iE "FOO|text" file.txt | tail -n 1






                                share|improve this answer










                                New contributor




                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.










                                Here's what I can get the output that is desired!



                                Match 1:



                                grep -iE "FOO|blank" toy.txt | head -2



                                Match 2:



                                grep -iE "FOO|blank" file.txt | grep also



                                Match 3:



                                grep -iE "FOO|blank" file.txt | tail -n 5 | head -n 3



                                Match 4:



                                grep -iE "FOO|text" file.txt | tail -n 2



                                Match 5:



                                grep -iE "FOO|text" file.txt | tail -n 1







                                share|improve this answer










                                New contributor




                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.









                                share|improve this answer



                                share|improve this answer








                                edited 1 hour ago





















                                New contributor




                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.









                                answered 1 hour ago









                                Vivek KanadiyaVivek Kanadiya

                                1547




                                1547




                                New contributor




                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.





                                New contributor





                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.






                                Vivek Kanadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                Check out our Code of Conduct.












                                • This assumes knowledge of the contents of the file.

                                  – Kusalananda
                                  1 hour ago











                                • yes this is based on knowledge of file

                                  – Vivek Kanadiya
                                  1 hour ago






                                • 1





                                  @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

                                  – ilkkachu
                                  1 hour ago

















                                • This assumes knowledge of the contents of the file.

                                  – Kusalananda
                                  1 hour ago











                                • yes this is based on knowledge of file

                                  – Vivek Kanadiya
                                  1 hour ago






                                • 1





                                  @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

                                  – ilkkachu
                                  1 hour ago
















                                This assumes knowledge of the contents of the file.

                                – Kusalananda
                                1 hour ago





                                This assumes knowledge of the contents of the file.

                                – Kusalananda
                                1 hour ago













                                yes this is based on knowledge of file

                                – Vivek Kanadiya
                                1 hour ago





                                yes this is based on knowledge of file

                                – Vivek Kanadiya
                                1 hour ago




                                1




                                1





                                @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

                                – ilkkachu
                                1 hour ago





                                @VivekKanadiya, I think the point here, as often in computing, is to automate a task so that it can be done automatically for multiple sets of data. A solution that only works for one particular input is hardly useful, instead of writing a set of commands to produce the output, we could just copy the required lines by hand. Note that the question also says, right there in the start, that the input shown is "a toy example".

                                – ilkkachu
                                1 hour ago

















                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Unix & Linux Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f507517%2fgrepping-string-but-include-all-non-blank-lines-following-each-grep-match%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                На ростанях Змест Гісторыя напісання | Месца дзеяння | Час дзеяння | Назва | Праблематыка трылогіі | Аўтабіяграфічнасць | Трылогія ў тэатры і кіно | Пераклады | У культуры | Зноскі Літаратура | Спасылкі | НавігацыяДагледжаная версіяправерана1 зменаДагледжаная версіяправерана1 зменаАкадэмік МІЦКЕВІЧ Канстанцін Міхайлавіч (Якуб Колас) Прадмова М. І. Мушынскага, доктара філалагічных навук, члена-карэспандэнта Нацыянальнай акадэміі навук Рэспублікі Беларусь, прафесараНашаніўцы ў трылогіі Якуба Коласа «На ростанях»: вобразы і прататыпы125 лет Янке МавруКнижно-документальная выставка к 125-летию со дня рождения Якуба Коласа (1882—1956)Колас Якуб. Новая зямля (паэма), На ростанях (трылогія). Сулкоўскі Уладзімір. Радзіма Якуба Коласа (серыял жывапісных палотнаў)Вокладка кнігіІлюстрацыя М. С. БасалыгіНа ростаняхАўдыёверсія трылогііВ. Жолтак У Люсiнскай школе 1959

                                Францішак Багушэвіч Змест Сям'я | Біяграфія | Творчасць | Мова Багушэвіча | Ацэнкі дзейнасці | Цікавыя факты | Спадчына | Выбраная бібліяграфія | Ушанаванне памяці | У філатэліі | Зноскі | Літаратура | Спасылкі | НавігацыяЛяхоўскі У. Рупіўся дзеля Бога і людзей: Жыццёвы шлях Лявона Вітан-Дубейкаўскага // Вольскі і Памідораў з песняй пра немца Адвакат, паэт, народны заступнік Ашмянскі веснікВ Минске появится площадь Богушевича и улица Сырокомли, Белорусская деловая газета, 19 июля 2001 г.Айцец беларускай нацыянальнай ідэі паўстаў у бронзе Сяргей Аляксандравіч Адашкевіч (1918, Мінск). 80-я гады. Бюст «Францішак Багушэвіч».Яўген Мікалаевіч Ціхановіч. «Партрэт Францішка Багушэвіча»Мікола Мікалаевіч Купава. «Партрэт зачынальніка новай беларускай літаратуры Францішка Багушэвіча»Уладзімір Іванавіч Мелехаў. На помніку «Змагарам за родную мову» Барэльеф «Францішак Багушэвіч»Памяць пра Багушэвіча на Віленшчыне Страчаная сталіца. Беларускія шыльды на вуліцах Вільні«Krynica». Ideologia i przywódcy białoruskiego katolicyzmuФранцішак БагушэвічТворы на knihi.comТворы Францішка Багушэвіча на bellib.byСодаль Уладзімір. Францішак Багушэвіч на Лідчыне;Луцкевіч Антон. Жыцьцё і творчасьць Фр. Багушэвіча ў успамінах ягоных сучасьнікаў // Запісы Беларускага Навуковага таварыства. Вільня, 1938. Сшытак 1. С. 16-34.Большая российская1188761710000 0000 5537 633Xn9209310021619551927869394п

                                Беларусь Змест Назва Гісторыя Геаграфія Сімволіка Дзяржаўны лад Палітычныя партыі Міжнароднае становішча і знешняя палітыка Адміністрацыйны падзел Насельніцтва Эканоміка Культура і грамадства Сацыяльная сфера Узброеныя сілы Заўвагі Літаратура Спасылкі НавігацыяHGЯOiТоп-2011 г. (па версіі ej.by)Топ-2013 г. (па версіі ej.by)Топ-2016 г. (па версіі ej.by)Топ-2017 г. (па версіі ej.by)Нацыянальны статыстычны камітэт Рэспублікі БеларусьШчыльнасць насельніцтва па краінахhttp://naviny.by/rubrics/society/2011/09/16/ic_articles_116_175144/А. Калечыц, У. Ксяндзоў. Спробы засялення краю неандэртальскім чалавекам.І ў Менску былі мамантыА. Калечыц, У. Ксяндзоў. Старажытны каменны век (палеаліт). Першапачатковае засяленне тэрыторыіГ. Штыхаў. Балты і славяне ў VI—VIII стст.М. Клімаў. Полацкае княства ў IX—XI стст.Г. Штыхаў, В. Ляўко. Палітычная гісторыя Полацкай зямліГ. Штыхаў. Дзяржаўны лад у землях-княствахГ. Штыхаў. Дзяржаўны лад у землях-княствахБеларускія землі ў складзе Вялікага Княства ЛітоўскагаЛюблінская унія 1569 г."The Early Stages of Independence"Zapomniane prawdy25 гадоў таму было аб'яўлена, што Язэп Пілсудскі — беларус (фота)Наша вадаДакументы ЧАЭС: Забруджванне тэрыторыі Беларусі « ЧАЭС Зона адчужэнняСведения о политических партиях, зарегистрированных в Республике Беларусь // Министерство юстиции Республики БеларусьСтатыстычны бюлетэнь „Полаўзроставая структура насельніцтва Рэспублікі Беларусь на 1 студзеня 2012 года і сярэднегадовая колькасць насельніцтва за 2011 год“Индекс человеческого развития Беларуси — не было бы нижеБеларусь занимает первое место в СНГ по индексу развития с учетом гендерного факцёраНацыянальны статыстычны камітэт Рэспублікі БеларусьКанстытуцыя РБ. Артыкул 17Трансфармацыйныя задачы БеларусіВыйсце з крызісу — далейшае рэфармаванне Беларускі рубель — сусветны лідар па дэвальвацыяхПра змену коштаў у кастрычніку 2011 г.Бядней за беларусаў у СНД толькі таджыкіСярэдні заробак у верасні дасягнуў 2,26 мільёна рублёўЭканомікаГаласуем за ТОП-100 беларускай прозыСучасныя беларускія мастакіАрхитектура Беларуси BELARUS.BYА. Каханоўскі. Культура Беларусі ўсярэдзіне XVII—XVIII ст.Анталогія беларускай народнай песні, гуказапісы спеваўБеларускія Музычныя IнструментыБеларускі рок, які мы страцілі. Топ-10 гуртоў«Мясцовы час» — нязгаслая легенда беларускай рок-музыкіСЯРГЕЙ БУДКІН. МЫ НЯ ЗНАЕМ СВАЁЙ МУЗЫКІМ. А. Каладзінскі. НАРОДНЫ ТЭАТРМагнацкія культурныя цэнтрыПублічная дыскусія «Беларуская новая пьеса: без беларускай мовы ці беларуская?»Беларускія драматургі па-ранейшаму лепш ставяцца за мяжой, чым на радзіме«Працэс незалежнага кіно пайшоў, і дзяржаву турбуе яго непадкантрольнасць»Беларускія філосафы ў пошуках прасторыВсе идём в библиотекуАрхіваванаАб Нацыянальнай праграме даследавання і выкарыстання касмічнай прасторы ў мірных мэтах на 2008—2012 гадыУ космас — разам.У суседнім з Барысаўскім раёне пабудуюць Камандна-вымяральны пунктСвяты і абрады беларусаў«Мірныя бульбашы з малой краіны» — 5 непраўдзівых стэрэатыпаў пра БеларусьМ. Раманюк. Беларускае народнае адзеннеУ Беларусі скарачаецца колькасць злачынстваўЛукашэнка незадаволены мінскімі ўладамі Крадзяжы складаюць у Мінску каля 70% злачынстваў Узровень злачыннасці ў Мінскай вобласці — адзін з самых высокіх у краіне Генпракуратура аналізуе стан са злачыннасцю ў Беларусі па каэфіцыенце злачыннасці У Беларусі стабілізавалася крымінагеннае становішча, лічыць генпракурорЗамежнікі сталі здзяйсняць у Беларусі больш злачынстваўМУС Беларусі турбуе рост рэцыдыўнай злачыннасціЯ з ЖЭСа. Дазволіце вас абкрасці! Рэйтынг усіх службаў і падраздзяленняў ГУУС Мінгарвыканкама вырасАб КДБ РБГісторыя Аператыўна-аналітычнага цэнтра РБГісторыя ДКФРТаможняagentura.ruБеларусьBelarus.by — Афіцыйны сайт Рэспублікі БеларусьСайт урада БеларусіRadzima.org — Збор архітэктурных помнікаў, гісторыя Беларусі«Глобус Беларуси»Гербы и флаги БеларусиАсаблівасці каменнага веку на БеларусіА. Калечыц, У. Ксяндзоў. Старажытны каменны век (палеаліт). Першапачатковае засяленне тэрыторыіУ. Ксяндзоў. Сярэдні каменны век (мезаліт). Засяленне краю плямёнамі паляўнічых, рыбакоў і збіральнікаўА. Калечыц, М. Чарняўскі. Плямёны на тэрыторыі Беларусі ў новым каменным веку (неаліце)А. Калечыц, У. Ксяндзоў, М. Чарняўскі. Гаспадарчыя заняткі ў каменным векуЭ. Зайкоўскі. Духоўная культура ў каменным векуАсаблівасці бронзавага веку на БеларусіФарміраванне супольнасцей ранняга перыяду бронзавага векуФотографии БеларусиРоля беларускіх зямель ва ўтварэнні і ўмацаванні ВКЛВ. Фадзеева. З гісторыі развіцця беларускай народнай вышыўкіDMOZGran catalanaБольшая российскаяBritannica (анлайн)Швейцарскі гістарычны15325917611952699xDA123282154079143-90000 0001 2171 2080n9112870100577502ge128882171858027501086026362074122714179пппппп