The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-05-2005
dbrundrett dbrundrett is offline
Registered User
  
 

Join Date: Jan 2002
Posts: 60
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
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:20 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0