Code Files

csv2api-groupmembers.awk

Generated on Tue Dec 05 17:39:06 Eastern Standard Time 2006 from csv2api-groupmembers.awk


# Program   : CSV2API-groupmembers.awk
# Purpose   : Convert .CSV file into API input file for Group Membership
# Date      : 26 June 2006
# 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      : Input file created by GWCONV
#           : Input file MUST have proper API file headers:
#             "Domain","Post-Office","Object","Last-Name","First-Name","Group-Domain","Group-Post-Office","Group-Name","Participation"


# Usage     : gawk -f CSV2API-groupmembers.awk -f library.awk -v GROUPDOMAIN=domain -v GROUPPOSTOFFICE=postoffice -v GROUPOBJECT=groupobject inputfile.csv > outputfile.api


BEGIN   {   



            # Output the API file headers
	    	print("WPC-API= 1.2; ")
		    print("Header-Char= T50; ")
		    print("Msg-Type= ADMIN; ")
		    print("")


	}

$0 == "====="   {   exit ;
}


FNR == 1    {   getheaders($0,fieldname) ;
#               numfields = parsecsv($0,headers)
#               for(i=1; i<= numfields; i++)    # invert header names
#                   fieldname[headers[i]] = i
}

FNR != 1    {   parsecsv($0,fields)

                print("DS-Group=")
                print("  Domain= "      GROUPDOMAIN     ";")
                print("  Post-Office= " GROUPPOSTOFFICE ";")
                print("  Object= "      GROUPOBJECT     ";")
                print("  Member=")
                print("    Operation= Add;")
                print("    Object-Type= User;")
                print("    Domain= "      fields[fieldname["Domain"]]      ";")
                print("    Post-Office= " fields[fieldname["Post-Office"]] ";")
                print("    Object= "      fields[fieldname["Object"]]      ";")     
                print("  ;")
                print(";")
                print("")
}

END     {   print("")
            print("-END-")
}
   

1 files processed.