The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular Expressions in If clause Raamc Shell Programming and Scripting 3 12-30-2008 11:01 AM
Conditonal clause in expect. akbar Shell Programming and Scripting 1 05-13-2008 07:28 PM
if clause palmer18 UNIX for Dummies Questions & Answers 3 08-08-2007 09:22 AM
building a SET clause in shell script shalua Shell Programming and Scripting 14 04-10-2007 06:34 PM
if clause in AWK END block not working. satnamx Shell Programming and Scripting 1 04-21-2006 06:29 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 02-06-2009
MaestroRage MaestroRage is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 20
having trouble with using if clause in AWK

The goal:
I have a list of people in teams. The list looks something like this

$1 = Job Position (marketing, IT, PR)
$2 = Name
$3 = Team Name
$4 = Targeted member (somebody in field 2 targets somebody else)
$5 = Employment Status (full time/part time/etc)

The idea is to search through the second field and spit out the lines that have the search results. The problem is since everybody who is in field 2 is also in field 4 (since everybody is targetted at least once) I'm getting double the results I want. I just want to search through the second field.

I'm trying to have a simple line of code that will look into the second field of a list, and use a regular expression to search that field and print it out. This is what I have, which I think should work, but it won't, and i'm fresh out of ideas. Any assistance would be helpful.

like

awk -F, ' /John/{print $0}' myfile

does the trick, it finds any line with john, fantastic. HOWEVER, my goal is to find all the Johns in ONE field.

awk -F, ' { if($4=="John") print $0} ' myfile

now this line of code should work (and returns nothing even when the first line returns the correct entries) but even if it did, it finds precisely John, where i'd also like to find any name that might make up John, ie, ohn.

I know that sounds like a grep problem but i'm having trouble dealing with grep even more then awk which i'm sure is how to go about doing this problem.

any and all help greatly appreciated.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0