![]() |
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 |
| Comparing two files | ragavhere | Shell Programming and Scripting | 32 | 12-04-2008 01:24 PM |
| Comparing two files | superstar003 | Forum Support Area for Unregistered Users & Account Problems | 1 | 05-08-2008 03:34 AM |
| Comparing two files.. | padarthy | Shell Programming and Scripting | 1 | 08-29-2007 08:01 AM |
| Comparing two files... | paqman | Shell Programming and Scripting | 12 | 08-08-2007 03:45 AM |
| comparing shadow files with real files | terrym | UNIX for Advanced & Expert Users | 4 | 02-09-2007 02:38 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | 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 |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|