1

In my case I want to grep lines which have number 4 in fourth column. Fourth column is last column. Columns are separated with space. I have this command:

grep -P '^([^\s]*\s){3}4

But that greps lines which contains nubers which strats with 4 like for example: 45, 4768, but I want that this works only for number 4.

That just doesn't work:

grep -P '^([^\s]*\s){3}4\n
Michael Albers
  • 3,721
  • 3
  • 21
  • 32
Marta Koprivnik
  • 385
  • 2
  • 3
  • 10

1 Answers1

2
 awk '{print $4}' | grep ^4$

I personally think its more clear if you use awk to get the column, then you can add a $ which matches the end of the line.

You also may need a caret to match only lines beginning with and ending with a 4.

bodangly
  • 2,473
  • 17
  • 28