|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
AWK - Different outputs *Question*
I'm having a small issue with AWK: I run this in PUTTY: Code:
awk 'BEGIN{FS=","}NR==FNR{A[$1]=$1;next}{if (A[$1]==$1) print $0}' FILE1 FILE2And it gives me the output that I expect. I wanted to create a file.awk file that i could just run instead of typing this out all the time. But its not giving my expected output. Here is what I did: Code:
#VLOOKUP type funtion useing AWK
BEGIN{FS=","}
NR==FNR
{A[$1]=$1;next}
{if (A[$1]==$1) print $0}Then I run this: Code:
awk -f ultVlookup.awk FILE1 FILE2 But I'm not getting the same results. What am I doing wrong? |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
The NR==FNR controls whether the code block behind it runs. When you put the code block on a different line, the statement is used for a different purpose -- determines whether the line prints. And the code block, without anything in front of it, runs every line, and the last line is never run because of the 'next' in the line above. Code:
BEGIN{ FS="," }
NR==FNR {A[$1]=$1;next}
{if (A[$1]==$1) print $0} |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| create outputs from other command outputs | rajsharma | Shell Programming and Scripting | 1 | 07-14-2010 07:43 AM |
| strcat outputs garbage | airon23bball | Programming | 2 | 05-25-2010 01:57 PM |
| compare 2 outputs | melanie_pfefer | Shell Programming and Scripting | 1 | 05-21-2008 09:20 AM |
| Printing outputs using awk. | Krrishv | Shell Programming and Scripting | 4 | 01-09-2007 06:31 AM |
| I may have accidentally redefined one of the outputs... | joang | Solaris | 2 | 03-22-2005 09:12 AM |
|
|