#!/bin/awk -f BEGIN { # A record is an IE heading RS = "-- =+\n-- IE: [A-Z][A-Za-z0-9-]+" # A field is a line FS = "\n" ORS = "" # Usage explanation if (ARGC != "3") { print "Usage: " ARGV[0] "module.asn module-modified.asn" print "Creates cr-module.asn and cr-module-modified.asn only including IEs" print "that are different between module.asn and module-modified.asb" exit } file = "origin" } BEGINFILE { i = 1 ie_header = "" } { if (ie_header != "") { split(ie_header, header_fields, "-- IE: ") ie_name = header_fields[2] module_ie[file][i] = ie_name module_ie_def[file][i] = ie_header $0 i++ } ie_header = RT } ENDFILE { file = "modified" } END { stripped_origin = "stripped_" ARGV[1] stripped_modified = "stripped_" ARGV[2] i_origin = 1 i_modified = 1 # Process IEs of the original .asn while (module_ie["origin"][i_origin] != "") { i_modified_search = i_modified # Search possibly until the end in the modified .asn for the same IE name while ((module_ie["modified"][i_modified_search] != "") && (module_ie["modified"][i_modified_search] != module_ie["origin"][i_origin])) { i_modified_search++ } # If the IE of the original .asn was found in the modified .asn if (module_ie["modified"][i_modified_search] == module_ie["origin"][i_origin]) { # Any IE in the modified .asn that was skipped is new, write it to the stripped modified file i = i_modified while (i < i_modified_search) { print module_ie_def["modified"][i] > stripped_modified i++ } # If they are different if (module_ie_def["modified"][i_modified_search] != module_ie_def["origin"][i_origin]) { print module_ie_def["origin"][i_origin] > stripped_origin print module_ie_def["modified"][i_modified_search] > stripped_modified } # Continue where we are i_modified = i_modified_search + 1 } # The IE of the original .asn was entirely deleted else { print module_ie_def["origin"][i_origin] > stripped_origin } i_origin++ } while (module_ie["modified"][i_modified] != "") { print module_ie_def["modified"][i_modified] > stripped_modified i_modified++ } }