Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing multiline records

Status
Not open for further replies.

Kipnep70

Technical User
Nov 18, 2003
81
0
0
US
Is awk capable of comparing a multilined record to a baseline record and outputing the difference?

For example..

Record 1 (Base line)

Code:
--------------
Name: Joseph Smith
Phone: 555-555-1234
Address: 801 Somewhere Ln.
Schedule: 08:00 - 17:00
----------------

Record 2

Code:
--------------
Name: Joseph Smith
Phone: 555-555-9876
Address: 801 Somewhere Ln.
Schedule: 08:00 - 20:00
----------------


Desired output:

Code:
--------------
Name: Joseph Smith
Phone: 555-555-9876
Schedule: 08:00 - 20:00
----------------


I need the "Name:" field to identify what the record is and then I would like just the altered fields listed in the output. I'm trying to use this concept for auditing purposes.

If this is possible then please let me know what "concepts" of awk I would need to use to get this to work. I'm pretty new to awk but I have confidence that I could figure it out with a little help -- I just don't know how to do the comparing. of Field N from record 1 to Field N of Record 2.

 
If you have GNU awk you could redefine RS (the record separator) to be --+. Other awks do not support regex for RS.

Personally I would simply load all of the fields into associative arrays indexed by the persons' names when processing the first file, and then compare them individually when processing the second file.

Annihilannic.
 
Yeah, assoc array would be my suggestion too.

Also, be careful about stripping spaces and punctuation from the name if you are using the name as an index.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top