![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
| join two files | koti_rama | Shell Programming and Scripting | 5 | 08-05-2008 05:20 AM |
| Join two files | koti_rama | Shell Programming and Scripting | 4 | 06-10-2008 07:15 AM |
| how to join files | jxh461 | UNIX for Dummies Questions & Answers | 5 | 08-23-2007 08:11 AM |
| join files | mohan705 | Shell Programming and Scripting | 3 | 03-15-2007 06:51 AM |
| Join Files | choppas | Shell Programming and Scripting | 2 | 10-18-2006 11:03 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Left join on files using awk
Quote:
Quote:
Quote:
Code:
nawk 'NR==FNR{a[$1];next} {if($1 in a) print $1,"Found" else print}' OFS="," File_B File_A
|
|
||||
|
well this was easy, you are missing on the syntax
nawk 'NR==FNR{a[$1];next} {if($1 in a) print $1,"Found";print}' OFS="," File_B File_A -----Post Update----- sample output bash-3.00$ nawk 'NR==FNR{a[$1];next} {if($1 in a) print $1,"Found";print}' OFS="," File_B File_A NY,Found NY NJ,Found NJ PA CA,Found CA VA,Found VA TN |
|
||||
|
Quote:
This is not the output i am looking for. please see the required output |
|
||||
|
if you have Python, an alternative
Code:
#!/usr/bin/env python
file2=[i.split()[0] for i in open("file2").read().split("\n")]
for line in open("file1"):
line=line.strip().split()
if line[0] in file2:
print line[0]," found"
else:
print line[0],","
Code:
# ./test.py NY found NJ found PA , CA found VA found TN , |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|