![]() |
|
|
grep unix.com with google
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Our Members | 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. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
Diff between 2 files using awk
Hi Experts,
Could you please help me to find the difference between two files. I tried the diff command but did not like the output as it contained < and > signs and the line numbers. Is it possible to do something using awk? I have two files, say File1.txt contains 5 values and File2.txt contains only 2 values of what File1.txt contains. I want a command or script that will list me the 3 missing values from File2.txt. Here are the examples File1.txt 034J 025J-01 045k 089G-02 04J01 File2.txt 025J-01 04J01 Output.txt 034J 045k 089g-02 Any help is highly appreciated. Thanks in advance |
|
|||
|
Easier with grep: Code:
grep -vf file2 file1 034J 045k 089G-02 Or if you still want to use awk: Code:
awk 'NR == FNR { A[$0]=1; next } !A[$0]' file2 file1
034J
045k
089G-02
Last edited by scottn; 11-30-2009 at 08:52 AM.. Reason: typo |
|
|||
|
or diff... 'man diff ' , I'm pretty sure there's a way to only output differences.
EDIT: probably not so useful...even $diff --suppress-common-lines file1 file2 still outputs the line numbers as well. Last edited by gcampton; 11-30-2009 at 10:04 AM.. |
|
|||
|
Diff between 2 files using awk
Hi Scottn,
Many thanks for a quick response. I tried both you solutions. with the grep I get the following message: grep: illegal option -- f usage: grep -hblcnsviw pattern file . . . with the awk script i get awk: syntax error near line 1 awk: bailing out near line 1 I used the commands exactly the way shown (obeviously replacing with the actual file names) could you spot the mistake here please!! Thanks again |
|
|||
|
Hi,
Any solution to this problem? I have the same doubt Thanks |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| diff of files | giri_luck | Shell Programming and Scripting | 12 | 09-17-2009 06:02 AM |
| Diff b/w 2 files | ecearund | Shell Programming and Scripting | 1 | 07-16-2009 02:39 AM |
| Diff online files | nottrobin | UNIX for Advanced & Expert Users | 2 | 01-06-2009 06:04 PM |
| Find duplicates from multuple files with 2 diff types of files | ricky007 | Shell Programming and Scripting | 2 | 03-04-2008 01:46 PM |
| diff 2 files; output diff's to 3rd file | blt123 | Shell Programming and Scripting | 2 | 05-28-2002 12:29 PM |