LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   AWK to perform like GREP (https://www.linuxquestions.org/questions/linux-newbie-8/awk-to-perform-like-grep-819347/)

chuafengru 07-12-2010 02:55 AM

AWK to perform like GREP
 
Hi guys,

Im trying to use awk to do matching in only a specific column

example.txt:
www.google.com www.example.com
www.google.com/search www.example2.com

i used:

awk '{ (if $1 == "http://www.google.com") print $2}' example.txt

this awk statement only returns the first line, and i cant seems to make it perform in a way to match based on keywords like GREP. Is there any way to make display the other lines which contains "google" also?

druuna 07-12-2010 03:11 AM

Hi,

If you want to search field one for (part of) a string:

awk '$1 ~ /www.google.com/ { print $2 }' example.txt

If the search string should match anywhere in the line (all fields):

awk '/www.google.com/ { print $2 }' example.txt

Hope this helps.


All times are GMT -5. The time now is 02:11 AM.