Newbee
Newbee

Reputation: 817

how to extract two words from a string using awk?

I have the below string:

70171  32982  0 17:44 pts/5    00:00:00 grep persist

Im trying to extract the words "grep" & "persist" from the above string.

I tried using awk -F' ' '{print $8,$9}' but that's not giving me the expected result.

Can someone tell me how it can be done using awk command.

Upvotes: 0

Views: 1385

Answers (1)

karakfa
karakfa

Reputation: 67467

awk default field separator handle spaces. If you want to extract the last two fields perhaps

$ awk '{print $(NF-1),$NF}' file

Upvotes: 2

Related Questions