Kerwin
Kerwin

Reputation: 339

How to grep a multiple pattern per line

lot:1, callback:0, header:x, parse:x,
lot:2, callback:0, header:y, parse:x,
lot:3, callback:0, header:x, parse:x,
lot:4, callback:0, header:x, parse:x,
lot:5, callback:0, header:y, parse:x,

Tried grep -e "lot:" -e "header:" but it only highlights the -e pattern.

Expected output should be

lot:1, header:x,
lot:2, header:y,
lot:3, header:x,
lot:4, header:x,
lot:5, header:y,

Upvotes: 1

Views: 202

Answers (1)

Kent
Kent

Reputation: 195059

give this a try:

grep 'lot:.*header:' 

This will list all lines containing lot:........header:....

If you want to get exact the output you posted in question, you can turn to awk:

awk -F', ' '$1~/^lot:/ && $3~/^header:/{print $1 FS $3}' file

Upvotes: 2

Related Questions