views:

63

answers:

3

Hi,

I have many lines of form: A:B:C

I want to print those lines(complete) where the 3rd field (fields separated by :) contain a certain pattern.

Example:

new/old:california/new york:/ms/dist/fx/PROJ/fx/startScript

new/old:startScript/new york:/ms/dist/fx/PROJ/fx/stopScript

When searching for pattern startScript, the 1st line should be printed and not the 2nd one.

Thanks,

Jagrati

+1  A: 

The general solution is to use awk but it is worth noting that in your specific example there is a much simpler solution - you can just use grep:

grep 'startScript$' yourfile
Mark Byers
The 3rd field can contain the pattern (startScript in this case) in any form. This was just an example. The pattern may not be prefixed by /ms/dist/fx and so on.
learnerforever
+7  A: 

Separate on colon, then check third field:

awk -F : '$3 ~ /startScript/ { print }'
Sjoerd
A: 
awk -F":" '$3~/startScript$/' file
ghostdog74