user2api-del.awk
Generated on Tue Dec 05 17:39:06 Eastern Standard Time 2006 from user2api-del.awk
# Program : USER2API-DEL.AWK
# Purpose : Convert a Comma Separated Value list with User data into an API file to DELETE objects
# Date : 6 July 2005
# Author : Bob Jonkman <bjonkman@sobac.com>
# Copyright 2008 Bob Jonkman and/or SOBAC Microcomputer Services
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Note : The input file MUST have proper API field headers in the first record
BEGIN { FS= "," ;
OFS= "" ;
QUOTE = "\"" ;
COMMA = "," ;
FIELD_SEPARATOR = COMMA
FIELD_DELIMITER = QUOTE
# Output the API file headers
print("WPC-API= 1.2; ");
print("Header-Char= T50; ");
print("Msg-Type= ADMIN; ");
print("");
}
##### Read the headers #####
NR == 1 { numfields = parsecsv($0,headers) ;
# create reverse lookup for fieldnames, ie. fieldnumber["Department"]=1, fieldnumber["Division"]=2 &c.
for (i=1; i <= numfields; i++)
{
# print("##### DEBUG ##### i= " i " headers[i]= " headers[i] ) ;
fieldnumber[headers[i]] = i;
}
}
##### End of Read the Headers #####
##### Read and output the data #####
(FNR > 1) && ($0 != "") { parsecsv($0,fieldarray);
print("DS-User= ");
print(" Operation= Delete;" );
print(" Domain= " fieldarray[fieldnumber["Domain"]] ";") ;
print(" Post-Office= " fieldarray[fieldnumber["Post-Office"]] ";") ;
print(" Object= " fieldarray[fieldnumber["Object"]] ";") ;
print(";");
print("");
}
##### End of Read and output the data #####
END { print("-END- ") # Output the API file footer
}
# EOF: USER2API.AWK
1 files processed.