0

If I want to Search "Finnish" then I want my output will be like

Raamatun tutkisteluja IV, mennessä Charles T. Russell                    56898
 [Subtitle: Harmagedonin taistelu]
 [Language: Finnish]

How to find the chunk of string?????

But My File Content is :

TITLE and AUTHOR                                                     ETEXT NO.

Aspects of plant life; with special reference to the British flora,      56900
 by Robert Lloyd Praeger

The Vicar of Morwenstow, by Sabine Baring-Gould                          56899
 [Subtitle: Being a Life of Robert Stephen Hawker, M.A.]

Raamatun tutkisteluja IV, mennessä Charles T. Russell                    56898
 [Subtitle: Harmagedonin taistelu]
 [Language: Finnish]

Raamatun tutkisteluja III, mennessä Charles T. Russell                   56897
 [Subtitle: Tulkoon valtakuntasi]
 [Language: Finnish]
2
  • Can you be more exact about 'before and after' ? Do you want the line above '[Language: Finnish]'
    – BlackPearl
    Apr 10, 2019 at 14:48
  • Assuming you have a Linux based system. It looks like your text file contains a set of records which are separated from one another by means of empty lines. You can easily search through such a file by means of awk with the record separator RS an empty string. This would create the command awk -v RS="" -v ORS="\n\n" '/Finnish/' file.txt. More about awk on catonmat.net/blog/awk-book and stackoverflow.com/tags/awk/info
    – kvantour
    Apr 11, 2019 at 10:03

1 Answer 1

-1

grep -A number_of_lines_after -B number_of_lines_before Finnish file

1
  • In my file, there is all the book information store. So, When I search using author name then i need all book info of that author like book name, author and textno. For example, If I search by Finnish then Output will be below. Raamatun tutkisteluja IV, mennessä Charles T. Russell 56898 [Subtitle: Harmagedonin taistelu] [Language: Finnish] and in my file, all book info is separated with newline Apr 10, 2019 at 15:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.