02-06-2009
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.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello all...
I have a slight problem in my awk script...
I have a script which checks a csv file and keeps a count of any invalid records and then if it finds any, exits with a code of 1. problem is it dosnt seem to work properly :rolleyes: Everthing seem to work interms of the stats output,... (1 Reply)
Discussion started by: satnamx
1 Replies
2. Shell Programming and Scripting
This is probably a fairly simple question but I cant seem to get it to work.
Im trying to multiply an entire column in a file by a variable in my bash script but just cant seem to get it to work with awk.
Here is what I'm trying
$varr is some value
$line is my file
awk '{print... (1 Reply)
Discussion started by: RichieFondel
1 Replies
3. Shell Programming and Scripting
Again, I am in need of some advice.
Earlier I was shown how to have awk create folders for me. That was so cool and helpful, but now I am exploring the posibilities of combining operations with bash scripts.
Now, I am creating the directories with the bash script, and then I want awk to... (1 Reply)
Discussion started by: ccox85
1 Replies
4. Shell Programming and Scripting
Hi all,
I'm writing a program in bourne shell that compresses a file 3 different ways then displays a table of data with the compression type, original file size, compressed size and compression ratio. I've written most of it but reached 2 problems that won't allow me to finish it correctly.
The... (2 Replies)
Discussion started by: javajynx
2 Replies
5. Shell Programming and Scripting
Hello all,
Please help me in letting me know the function of *substr* function in awk...
actually i am new with this function i can play with awk but for this function needs your help in making me understand the correct way of using it.
I am writting a code please advice regarding this... (4 Replies)
Discussion started by: jojo123
4 Replies
6. UNIX and Linux Applications
Hi to all! I 'm new in unix programing so... may be I decided a wrong tool to solve the problem but anyway... all road goes to rome jajaja.
My question is: There is any way to print date at the END clause of an AWK script. I mean, I'm writing a tool with AWK and the results are redirected to a... (4 Replies)
Discussion started by: fmeriles
4 Replies
7. Shell Programming and Scripting
Hello all,
I'm a beginner to shell/ awk script writing, and I'm trying to do something that looks like it shouldn't be (too) hard at all to do, but unfortunately, I can't seem to be able to find the right way to do it with awk.
I need to look for the time several processes start & end in a... (5 Replies)
Discussion started by: Muadib
5 Replies
8. UNIX for Dummies Questions & Answers
I am trying to figure awk.
I have a file in my home directory called testawk.sh, have made it executable, and have run it... But don't see any output.
This is the contents of the file:
#!/usr/bin/awk -f
{ print " - HI -" }I enter ./testawk.sh in the prompt, press enter, and watch as the... (2 Replies)
Discussion started by: matthewden
2 Replies
9. Shell Programming and Scripting
Hi,
I need to read a string with ; separated using loop one filed by one field and perform some operation. Can you please check and let me know how to print command parameterised.
key=phani;ravi;kiran
number_of_keys=`echo $key|awk '{print NF}' FS=';'`
for (( i = 1; i <= $number_of_keys;... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies
10. Shell Programming and Scripting
Hi,
I have 2 .txt pads containing data.
I need a script which reads content of one .txt file, performs some operations and calculates a number which is stored in a variable.
Now , all the content of another .txt pad should be appended to first .txt pad at pre calculated nth line number.
... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies
LEARN ABOUT HPUX
xmtargetsarecompatible
XmTargetsAreCompatible(library call) XmTargetsAreCompatible(library call)
NAME
XmTargetsAreCompatible -- A function that tests whether the target types match between a drop site and source object
SYNOPSIS
#include <Xm/DragDrop.h>
Boolean XmTargetsAreCompatible(
Display *display,
Atom *export_targets,
Cardinal num_export_targets,
Atom *import_targets,
Cardinal num_import_targets);
DESCRIPTION
XmTargetsAreCompatible determines whether the import targets of the destination match any of the export targets of a source. If there is
at least one target in common, the function returns True.
display Specifies the display connection.
export_targets
Specifies the list of target atoms associated with the source object. This resource identifies the selection targets the source
can convert to.
num_export_targets
Specifies the number of entries in the list of export targets.
import_targets
Specifies the list of targets to be checked against the XmNexportTargets of the source associated with the specified DragContext
num_import_targets
Specifies the number of entries in the import_targets list.
RETURN
Returns a Boolean value that indicates whether the destination targets are compatible with the source targets. If there is at least one
target in common, the routine returns True; otherwise, returns False.
RELATED
XmDragContext(3) and XmDropSite(3).
XmTargetsAreCompatible(library call)