[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SLUG] awk scripting help (cvs file to gnats config)



Hello slug ppl,

I was wondering if anyone could help me with a awk script I was writing.

I found this funny thing where a if/else statement in awk process both
the arguments after the if and the else.

The script's purpose is to read a CSV file created by *gulp* Microsoft
Exchange and to create a submitters and addresses file for GNU gnats bug
tracking tool.

here is the portion that I am having trouble with:

        x = split($csv_namelu["E-mail Addresses"],emailsplit,"%")
        for (i = 1; i <= x; i ++) {
           if (match(emailsplit[i],/SMTP:[A-Z,a-z]*\.[A-Z,a-z]*@nospam./)) {
                print "if was true"
                emailaddr = substr(emailsplit[i],6)
                emailaddr = tolower(emailaddr)
           } else {
                print "if was false"
                emailaddr = ""
           }

the if statement above this with the same match() function works ok. 
 - yes I checked the brackets match up... um so I'm a little confused
here.

I've attached the script. All it does is parse in some variables so far.

Also attached is the sort of data it reads in from the CSV file (for
those fortunate enough not to have MS exchange anywhere nearby).

Any help would be greatly appreciated!

Luke McKee
Utilux ISD
Obj-Class,First Name,Last name,Display Name,Alias Name,Directory Name,Primary Windows NT Account,Home-Server,E-mail address,E-mail Addresses,Members,Obj-Container,Hide from AB
Mailbox,luke,Mckee,Luke Mckee,lmc,lom,UTILUX\lmc,UTXEXG,,SMTP:luke.mckee@nospam.utilux.com%X400:c=AU;a= ;p=Utilux Pty Ltd;o=UTILUX;s=Mckee;g=Look;,,/o=Utilux Pty Ltd/ou=UTILUX/cn=Recipients,0
BEGIN{
	FS = ","
	OFS = ":"
}
{
   if ($1 == "Obj-Class") {
	for ( i = 1; i <= NF; i ++ ) {
		csv_rowlu[i] = $i
		csv_namelu[$i] = i
	}
   }
   else {
	lastname = $csv_namelu["Last name"]	
	firstname = $csv_namelu["First Name"]
        x = split($csv_namelu["Primary Windows NT Account"],ntsplit,"\\")
	ntdomain = ntsplit[1]
	ntuser = ntsplit[2]
	x = split ($csv_namelu["Obj-Container"],x500split,"=")
	for (i = 1; i <= x; i ++) {
	   if (match(x500split[i],/\/cn$/)) {
		containername = x500split[i + 1]
	   }
	}
	displayname = firstname " " lastname
	x = split($csv_namelu["E-mail Addresses"],emailsplit,"%")
	for (i = 1; i <= x; i ++) {
	   if (match(emailsplit[i],/SMTP:[A-Z,a-z]*\.[A-Z,a-z]*@nospam./)) {
                print "if was true"
		emailaddr = substr(emailsplit[i],6)
		emailaddr = tolower(emailaddr)
                print emailaddr
	   } else {
		print "if was false"
		emailaddr = ""
	   }
	}
	# elmininate records that are not needed
	#if (emailaddr == "") next 
	#if (csv_namelu["Hide from AB"]) == 1) next
   }
}