Displaying lines of a file where the second field matches a pattern

Howdy.

I know this is most likely possible using sed or awk or grep, most likely a combination of them together, but how would one go about running a grep like command on a file where you only try to match your pattern to the second field in a line, space delimited?

Example:

You are searching for xxx in each line of a file where the file is laid out as
aaa bbb ccc ddd eee
aaa bbb ccc ddd eee
Each one of those three letter groupings being any number of things. I only want to display the lines of the files where bbb = xxx.

Possible?

Thanks if anyone knows.

You can use awk or perl:

$
$ cat input.txt
aaa bbb ccc ddd eee
aaa xxx ccc ddd eee
aaa 123 ccc ddd eee
aaa xxx ccc DDD EEE
$
$ awk '{if ($2 == "xxx") {print}}' input.txt
aaa xxx ccc ddd eee
aaa xxx ccc DDD EEE
$
$ perl -ne '{split; print if $_[1] eq "xxx"}' input.txt
aaa xxx ccc ddd eee
aaa xxx ccc DDD EEE
$
$

And I'm sure there are other ways to do it as well.

tyler_durden

awk '$2=="xxx"' file

Thanks guys, it worked.