0

I have a log file that has 2 instances of 2 consecutive words on a line.

Example:

Process ID: 1034 Worker Process 4

I want to search for "Process ID" AND "Worker Process" on the same line.

The separate words "Process" or "ID" or "Worker" may also occur as separate words in the log that I do not want to find

Can you use " marks in a grep syntax.

Not sure how best to go about this. Googled this alot.

Thanks for any assistance.

Bart
  • 2,221

2 Answers2

0

Yes you can use " inside a grep pattern. Specifically you can use

grep 'Process ID.*Worker Process' yourfile

to match the two quoted patterns where they occur in a single line separated by arbitrary text.

See grep with logic operators for further discussion and alternate solutions.

steeldriver
  • 81,074
  • I tried : grep '"Process ID"."Worker Process"' and I get no hits, when I should. the complete string that could be in the log is "Process ID: 1034 Worker Process 4" no quotes. – OliversDad Aug 30 '19 at 15:26
  • @OliversDad apologies - since you specifically mentioned using " marks in the pattern, I assumed you literally wanted to match "Process ID" and "Worker Process"- please see the amended answer without the quotes – steeldriver Aug 30 '19 at 15:33
0

I think this would do, if I understand you correctly:

cd your_dir

grep -Ron "Process ID: [0-9]* Worker Process [0-9]*"

Go to the directory where the files are placed:

cd your_dir

Search recursively -R in the directory and retrieve only o the line you want,n will give you the line number.


Match the pattern Process ID: [0-9]* Worker Process [0-9]*


Given a file with content:

Process

Process ID: 1034 Worker Process 4

ID

Worker

Output:

a.txt:3:Process ID: 1034 Worker Process 4
c.txt:7:Process ID: 1034 Worker Process 4
b.txt:7:Process ID: 1034 Worker Process 4