pattern match .com in awk script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pattern match .com in awk script
# 1  
Old 05-11-2011
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
Code:
 if ( $i ~ /.com/ )

even escaping it doesn't help
Code:
 if ( $i ~ /\.com/ )


Last edited by Franklin52; 05-12-2011 at 03:29 AM.. Reason: Please use code tags
# 2  
Old 05-11-2011
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.
# 3  
Old 05-11-2011
using bash......

Code:
#!/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[i] )
 	
	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! Smilie


thnks anyways

Last edited by pludi; 05-12-2011 at 03:46 AM.. Reason: Please use code tags, thank you
This User Gave Thanks to shreeprabha For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filesystem pattern match in awk

Hi, I'm trying to grep appln processes using its filesystem and also using awk to get accurate results, however when i'm uisng the filesystem in awk statement i'm getting error. Requesting help. ps -eaf | grep ApplnName | awk '/ /opt/xxx/yyy / { print }' Trying with this above code; getting... (7 Replies)
Discussion started by: sam_bd
7 Replies

2. UNIX for Beginners Questions & Answers

awk script for pattern match and line break

Hi, I have input which reads like 9089.00 ----- kl jkjjljk lkkk; (909099) 9097.00 ----- HGJJHHJ jcxkjlkjvhvlk jhdkjksdfkhfskd 898.00 ----- HHHH I am trying to do something like this - As soon as I found pattern match "XYZ.00-----" it will insert a line break to the input and will go to... (3 Replies)
Discussion started by: Indra2011
3 Replies

3. Shell Programming and Scripting

awk to combine lines from line with pattern match to a line that ends in a pattern

I am trying to combine lines with these conditions: 1. First line starts with text of "libname VALUE db2 datasrc" where VALUE can be any text. 2. If condition1 is met then continue to combine lines through a line that ends with a semicolon. 3. Ignore case when matching patterns and remove any... (5 Replies)
Discussion started by: Wes Kem
5 Replies

4. Shell Programming and Scripting

Script to match a pattern and print only the pattern and after that

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ...... .......xyz: abz: ..... I have tried using awk and cut, bu the position of these values keep changing, so I can use awk and split it into columns. ... (14 Replies)
Discussion started by: Serena
14 Replies

5. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

6. Shell Programming and Scripting

AWK match $1 $2 pattern in file 1 to $1 $2 pattern in file2

Hi, I have 2 files that I have modified to basically match each other, however I want to determine what (if any) line in file 1 does not exist in file 2. I need to match column $1 and $2 as a single string in file1 to $1 and $2 in file2 as these two columns create a match. I'm stuck in an AWK... (9 Replies)
Discussion started by: right_coaster
9 Replies

7. UNIX for Dummies Questions & Answers

awk -repeated pattern match

Hi. How can I write this differently: awk '$3 ~ /0001/{print}' Is there a way to write 0001 differently. I am looking for the pattern 01, with 3 or more 0 and 3 or more 1 in a pattern. Thanks. (12 Replies)
Discussion started by: danieladna
12 Replies

8. Shell Programming and Scripting

Awk script to match pattern till blank line

Hi, I need to match lines after a pattern, upto the first blank line. Searched in web and some forums but coulnt find the answer. where <restart_step> = 10 -- Execute query 20 -- Write the contents to the Oracle table 30 -- Writing Contents to OUTPUT... (7 Replies)
Discussion started by: justchill
7 Replies

9. Shell Programming and Scripting

Use to awk to match pattern, and print the pattern

Hi, I know how to use awk to search some expressions like five consecutive numbers, , this is easy. However, how do I make awk print the pattern that is been matched? For example: input: usa,canada99292,japan222,france59664,egypt223 output:99292,59664 (6 Replies)
Discussion started by: grossgermany
6 Replies

10. Shell Programming and Scripting

want to pattern match using awk

Hello Friends, My script gives an output like below:- but i only want the red part to be displayed. how to i do that. I am enclosing my shell script after that. id='CCRCWebServerINSTALLDIR' id='AdministrationTools-CINSTALLDIR' id='AdministrationTools-ent-CINSTALLDIR'... (3 Replies)
Discussion started by: asirohi
3 Replies
Login or Register to Ask a Question