Skip to main content
deleted 208 characters in body; edited tags
Source Link
Braiam
  • 36.9k
  • 29
  • 114
  • 176

I am new to linux searching and would appreciate any help that can be provided. I would like to be able to perform a command line to execute my search.

I have a text file with multiple log data, I would like to search for 'Keyword-1' in a line, and when it finds the line, to search within that line for another keyword such as 'engine-1'. Then extract the section from the start of 'engine-1' until it reaches a different engine such as 'engine-2'. I would like all 'engine-1' section extracted, that includes all lines between the start and end of 'engine-1'. The end of 'engine-1' is defined by reaching any other number such as 'engine-2' or 'engine-xx'.

Note, not all lines contain the word engine, but I still want to extract the 'Data' between 'engine-1' start and 'engine-1' end.

Then moved on to the next section in the file and repeat the process by searching for keyword-1 first and finding out engine it uses, and extracted the start/end section of the new different engine. The link between all sections would be 'keyword-1'

The text file looks like this:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1


 Data engine-2
 Data engine-2
 Data
 Data
 Data engine-2
 Data engine-2

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

 Data engine-1
 Data engine-1 
 Data
 Data
 Data engine-1

Result should look like this after extraction:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

Any help would be greatly appreciated.

Thanks

I am new to linux searching and would appreciate any help that can be provided. I would like to be able to perform a command line to execute my search.

I have a text file with multiple log data, I would like to search for 'Keyword-1' in a line, and when it finds the line, to search within that line for another keyword such as 'engine-1'. Then extract the section from the start of 'engine-1' until it reaches a different engine such as 'engine-2'. I would like all 'engine-1' section extracted, that includes all lines between the start and end of 'engine-1'. The end of 'engine-1' is defined by reaching any other number such as 'engine-2' or 'engine-xx'.

Note, not all lines contain the word engine, but I still want to extract the 'Data' between 'engine-1' start and 'engine-1' end.

Then moved on to the next section in the file and repeat the process by searching for keyword-1 first and finding out engine it uses, and extracted the start/end section of the new different engine. The link between all sections would be 'keyword-1'

The text file looks like this:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1


 Data engine-2
 Data engine-2
 Data
 Data
 Data engine-2
 Data engine-2

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

 Data engine-1
 Data engine-1 
 Data
 Data
 Data engine-1

Result should look like this after extraction:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

Any help would be greatly appreciated.

Thanks

I have a text file with multiple log data, I would like to search for 'Keyword-1' in a line, and when it finds the line, to search within that line for another keyword such as 'engine-1'. Then extract the section from the start of 'engine-1' until it reaches a different engine such as 'engine-2'. I would like all 'engine-1' section extracted, that includes all lines between the start and end of 'engine-1'. The end of 'engine-1' is defined by reaching any other number such as 'engine-2' or 'engine-xx'.

Note, not all lines contain the word engine, but I still want to extract the 'Data' between 'engine-1' start and 'engine-1' end.

Then moved on to the next section in the file and repeat the process by searching for keyword-1 first and finding out engine it uses, and extracted the start/end section of the new different engine. The link between all sections would be 'keyword-1'

The text file looks like this:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1


 Data engine-2
 Data engine-2
 Data
 Data
 Data engine-2
 Data engine-2

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

 Data engine-1
 Data engine-1 
 Data
 Data
 Data engine-1

Result should look like this after extraction:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3
Source Link

Extract multiple lines with secondary keyword search

I am new to linux searching and would appreciate any help that can be provided. I would like to be able to perform a command line to execute my search.

I have a text file with multiple log data, I would like to search for 'Keyword-1' in a line, and when it finds the line, to search within that line for another keyword such as 'engine-1'. Then extract the section from the start of 'engine-1' until it reaches a different engine such as 'engine-2'. I would like all 'engine-1' section extracted, that includes all lines between the start and end of 'engine-1'. The end of 'engine-1' is defined by reaching any other number such as 'engine-2' or 'engine-xx'.

Note, not all lines contain the word engine, but I still want to extract the 'Data' between 'engine-1' start and 'engine-1' end.

Then moved on to the next section in the file and repeat the process by searching for keyword-1 first and finding out engine it uses, and extracted the start/end section of the new different engine. The link between all sections would be 'keyword-1'

The text file looks like this:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1


 Data engine-2
 Data engine-2
 Data
 Data
 Data engine-2
 Data engine-2

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

 Data engine-1
 Data engine-1 
 Data
 Data
 Data engine-1

Result should look like this after extraction:

 Data engine-1
 Data engine-1
 Data
 Data
 Data engine-1 **keyword-1**
 Data engine-1

 Data engine-3
 Data engine-3 
 Data
 Data
 Data engine-3 **keyword-1**
 Data engine-3

Any help would be greatly appreciated.

Thanks