string pattern ,files ,occurrences


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting string pattern ,files ,occurrences
# 1  
Old 04-23-2010
string pattern ,files ,occurrences

Hi ,
I want to create a shell script which will find the complexity of a sql script.Suppose a.sql holds the following two query --

Code:
select * from table1 a ,table2 b
 where a.column1=b.column1;
 
select * from table1 a ,(select * from table1 c ,table2 d where c.column1=d.column1) e 
where a.column2=e/column2 ;

Now the tables name would be in file say a.txt.My scripts should search the no of times they appear in a select statement and count.

for example for 1st query it should return 2 , for second statement 3.

Thanks and regards,
Anupam

Last edited by vgersh99; 04-23-2010 at 06:39 AM.. Reason: code tags, please!
# 2  
Old 04-23-2010
try this

Code:
awk '$0 ~ /^select/ {for (i=1;i<=NF;i++)if($i ~ /table/)cnt++;print "select",j+1,": ",cnt;cnt=0;j++}' a.sql


cheers,
Devaraj Takhellambam
# 3  
Old 04-23-2010
Hi Devaraj ,
Thanks for your promt reply.
But still I have a problem . The tables name would be in a text file a.txt . In your code you have not used that file . If you know sql then you would understand my problem more clearly . A code will be considered more complex if there is more joins of tables.

Thanks
Anupam
# 4  
Old 04-23-2010
Try to customized this to your needs

Code:
while read tabname
do
awk -v table=$tabname '$0 ~ /^select/ {for (i=1;i<=NF;i++)if($i ~ /table/)cnt++;print table,":select ",j+1,"has: ",cnt;cnt=0;j++}' a.sql
done < tablenames

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete multiple occurrences of the same pattern on a line but the first

The lines that I am trying to format look like Device ID: j01-01, IP address: 10.10.10.36, IP address: 10.10.10.35, IP address: 10.10.102.201, Platform: 8040, Capabilities: Host , Interface: GigabitEthernet9/45, Port ID (outgoing port): e0k,Here is what I have so far but it... (4 Replies)
Discussion started by: dis0wned
4 Replies

2. Shell Programming and Scripting

Remove duplicate occurrences of text pattern

Hi folks! I have a file which contains a 1000 lines. On each line i have multiple occurrences ( 26 to be exact ) of pattern folder#/folder#. # is depicting the line number in the file some text here folder1/folder1 some text here folder1/folder1 some text here folder1/folder1 some text... (7 Replies)
Discussion started by: martinsmith
7 Replies

3. UNIX for Advanced & Expert Users

sed REGEX to print multiple occurrences of a pattern from a line

I have a line that I need to parse through and extract a pattern that occurs multiple times in it. Example line: getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed, getInfoCall: info received please proceed,... (4 Replies)
Discussion started by: Vidhyaprakash
4 Replies

4. Shell Programming and Scripting

Print occurrences for pattern match

Hi All, I want to print all the occurrences for a particular pattern from a file. The catch is that the pattern search is partial and if any word in the file contains the pattern, that complete word has to be printed. If there are multiple words matching the pattern on a specific line, then all... (2 Replies)
Discussion started by: decci_7
2 Replies

5. Shell Programming and Scripting

Script to Serach pattern and give number of occurrences

Hi, I want a script which search for a pattern "good" in a huge file and provide me number of occurences of such pattern in a file. lets say i have a file test.txt contents as below good is good but good is sometime bad and sometime good you are very good and good is always good ... (7 Replies)
Discussion started by: sv0081493
7 Replies

6. Shell Programming and Scripting

remove all occurrences of a character at the beginning of a string

Hi there, i need some help to remove all occurrences of a certain character at the beginning of a string. Example: my string is 00102030 and i want to remove all zeros from beginning of string so the result is 102030 (3 Replies)
Discussion started by: gigagigosu
3 Replies

7. Shell Programming and Scripting

counting number of pattern occurrences

Hi All, Is it possible to count number of occurrences of a pattern in a single record using awk?? for example: a line like this: abrsjdfhafa I want to count the number of a character occurrences. but still use the default RS, I don't want to set RS to single character. (1 Reply)
Discussion started by: ghoda2_10
1 Replies

8. Shell Programming and Scripting

CSV: Replacing multiple occurrences inside a pattern

Greatings all, I am coming to seek your knowledge and some help on an issue I can not currently get over. I have been searching the boards but did not find anything close to this matter I am struggling with. I am trying to clean a CSV file and make it loadable for my SQL*Loader. My problem... (1 Reply)
Discussion started by: OCanada
1 Replies

9. Shell Programming and Scripting

Count the number of occurrences of a pattern between each occurrence of a different pattern

I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'. Here's a portion of the text I'm trying to parse: lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb registrations: key 4156 4353 0000 0000 ... (3 Replies)
Discussion started by: slipstream
3 Replies

10. UNIX for Dummies Questions & Answers

Search and Count Occurrences of Pattern in a File

I need to search and count the occurrences of a pattern in a file. The catch here is it's a pattern and not a word ( not necessarily delimited by spaces). For eg. if ABCD is the pattern I need to search and count, it can come in all flavors like (ABCD, ABCD), XYZ.ABCD=100, XYZ.ABCD>=500,... (6 Replies)
Discussion started by: tektips
6 Replies
Login or Register to Ask a Question