![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Comparing two files | ragavhere | Shell Programming and Scripting | 31 | 06-12-2008 01:12 AM |
| Comparing two files | superstar003 | Forum Support Area for Unregistered Users & Account Problems | 1 | 05-08-2008 12:34 AM |
| Comparing two files.. | padarthy | Shell Programming and Scripting | 1 | 08-29-2007 05:01 AM |
| Comparing two files... | paqman | Shell Programming and Scripting | 12 | 08-08-2007 12:45 AM |
| comparing shadow files with real files | terrym | UNIX for Advanced & Expert Users | 4 | 02-08-2007 10:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
awk - comparing files
I've been trying to use awk to compare two files that have pretty much the same data in apart from certain lines where in one file a fields value has changed. I want to print the line from the first file and the changed line from the second file.
At the moment, all I can get it to do is print the line that contains the changed value. Here's some example data: File1: 111:222:333:444 222:333:444:555 333:444:555:666 File2: 112:222:333:444 222:333:444:555 333:444:555:667 As you can see the first field in the first line in file2 has changed and also the last field in last line has changed. So I'm looking for the output to be something like: file1 old - 111:222:333:444 file2 new - 112:222:333:444 --------------------------- file1 old - 333:444:555:666 file2 new - 333:444:555:667 The awk I've written so far is: awk 'BEGIN { while (getline < "file1" > 0) arr[$0] = $0 } { if ($0 in arr) { continue } else { print NR" - file2 - "$0 print "-----------------------------------------------------------------------------------------------" } } ' file2 This only prints the line that has changed in the second file Can any one help? Cheers |
| Forum Sponsor | ||
|
|
|
|||
|
Comparing two files and getting the output
Quote:
I have 2 files File1.txt and File2.txt File1.txt 123|Rosy|Chicago| 234|stella|michigan| 999|Richard|NJ| File2.txt 123|Rosy|Chicago| 235|Stella|michigan| 999|Richard|NJ|ABN I want to compare the two files and get the output as below: Old:234|stella|michigan New:235|Stella|michigan| I used your above solution,but its giving error. I used the command awk -f db.awk File1.txt File2.txt Can someone help me in this regard? |
| Thread Tools | |
| Display Modes | |
|
|