pattern match .com in awk script

guys !

I want to search .com,.html files .....
how do I match pattern...?
here's wht I hv written

 if ( $i ~ /.com/ )

even escaping it doesn't help

 if ( $i ~ /\.com/ )

Please rewrite your post mentioning what Shell you are runnning (?csh) and show a complete script demonstrating how you invoked the script, what happened and what you expected to happen.

using bash......

#!/bin/gawk -f

BEGIN { FS = "\""
}

tolower($0) ~ /href | src/ {

	for ( i=1; i<=NF; i++ ) {

		if ( tolower($i) ~ /href/ ) {
			if ( tolower($i) ~ /com$/ )    
		    		web[$(i+1)]++
		
			else if ( $i ~ /.jpg/ || $i ~ /.jpeg/ || $i ~ /.gif/ || $i ~ /.png/ )	
		  		 img[$(i+1)]++
		
			else
		   		downl[$(i+1)]++	
		}
		
		else if ( tolower($i) ~ "src" ) 
			img[$(i+1)]++
	
	}	
}

END {
	print "\t S U M M A R Y\n\n"
	print "Filename \t Link 						\t # link appears\n"
	
	print "\n\t Group 1: Webpage Links\n" 
		for ( w in web )
			printf ( ""FILENAME" \t %s 				\t %d \n", w, web[w] )
	
	print "\n\t Group 2: Image Links\n "
		for ( i in img )
			printf ( ""FILENAME" \t %s 				\t %d \n", i, img )
 	
	print "\n\t Group 3: Other downloadable links"
		for ( d in downl )
			printf ( ""FILENAME" \t %s 				\t %d \n", d, downl[d] )

}

---------- Post updated at 11:58 PM ---------- Previous update was at 11:44 PM ----------

found the solution
instead of $i i should use $(i+1).....in the if statement
.......
rookie mistake! :slight_smile:

thnks anyways

1 Like