1833875 Members
1877 Online
110063 Solutions
New Discussion

grep functionality

 
SOLVED
Go to solution
Dave Walley
Frequent Advisor

grep functionality

Hi.

I have a file with multiple fields as follows

dwafcs is 7.3.4
dwerp is 8.1.7
pwcst is 7.3.4
pwoverp is 8.1.7

I want to select only those lines where the last letter of the first field is p, in the example above I would want lines 2 and 4. How can I do it?

Thanks in advance.

Dave
why do i do this to myself
2 REPLIES 2
Simon Hargrave
Honored Contributor
Solution

Re: grep functionality

In the simplest case: -

grep "^.*p " file

Except this will also match a line eg "pcswt ip 7.3.4" (since it's greedy by default). The following is the non-greedy equivelant and should do what you want: -

grep "^[^ ]*p " file
Sridhar Bhaskarla
Honored Contributor

Re: grep functionality

Hi Dave,

I will try to do it with awk assuming that the field is always the first one..

awk '$1 ~ /p$/ {print}' data

-Sri
You may be disappointed if you fail, but you are doomed if you don't try