LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-12-2010, 03:55 AM   #1
chuafengru
LQ Newbie
 
Registered: Jun 2010
Posts: 28

Rep: Reputation: 0
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?
 
Old 07-12-2010, 04:11 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
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.
 
1 members found this post helpful.
  


Reply

Tags
awk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use grep inside awk? Helene Programming 10 09-29-2015 09:48 PM
Using grep and awk to get IP address snowman81 Programming 12 08-25-2012 11:45 AM
help with grep/sed/awk nikunjbadjatya Programming 8 02-17-2010 08:29 PM
Grep and AWK keogk Linux - General 10 01-04-2010 09:03 PM
grep and awk error bazzano Programming 2 04-06-2009 01:01 AM


All times are GMT -5. The time now is 05:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration