How to find function name based on word search


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to find function name based on word search
# 1  
Old 07-14-2009
How to find function name based on word search

Hi All,

I want to find out function name based on word.
Here i ll give u one example

I have several files based on below format. file will start and ends with same name only

EX: file1.txt
Code:
public function calculate1()
{
 ----
 ----
 call Global Function1()
 ----
 ----
} END public function calculate1()
public function calculate2()
{
 ----
 ----
 call Global Function1()
 ----
 ----
} END public function calculate2()
public function calculate3()
{
 ----
 ----
 call Global Function1()
 ----
 ----
} END public function calculate3()
public function calculate4()
{
 ----
 ----
 ----
 ----
} END public function calculate4()

my requirement : I need to find out function names based on "call Global Function1()"

my output should be :
Code:
public function calculate1()
public function calculate2()
public function calculate3()

Can u give any idea...how to proceed....

Thanks in advance....

Last edited by radoulov; 07-14-2009 at 04:01 AM.. Reason: added code tags
# 2  
Old 07-14-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 09:14 AM ---------- Previous update was at 09:00 AM ----------

Use gawk, nawk or /usr/xpg4/bin/awk on Solaris:

Code:
awk '/^public function/, /END public function/ { 
  /^public function/ && fn = $0
  if ($0 ~ sc) print fn
  }' sc='call Global Function1' infile

# 3  
Old 07-14-2009
How to find function name based on word search

Just I want to display names of all the functions which are called "call Global Function1()".

so based on above file ( file1.txt) output should be

Code:
 
public function calculate1()
public function calculate2()
public function calculate3()

these functions are used to call
Code:
call Global Function1()

So please give me any idea how to proceed. I have basic knowlege of shell scripting.
# 4  
Old 07-14-2009
Did you try the awk code I posted?
# 5  
Old 07-14-2009
sorry ..i didn't try that. I think u posted above code before i updated.
Let u know after i try that.....
# 6  
Old 07-16-2009
hi radoulov,

Ur code is giving syntax errors ...i couldnt rectify....
Code:
 
awk '/^public function/, /END public function/ { 
  /^public function/ && fn = $0
  if ($0 ~ sc) print fn
  }' sc='call Global Function1' infile

[/CODE]

Im getting following errors :

awk: syntax error near line 2
awk: illegal statement near line 2
awk: illegal statement near line 3

If possible please tell me how to fix above syntax errors for "awk" code

But i tried like this. Its working.....

Code:
 
cat infile|while read line
do
        echo $line |tr -d " "|grep "publicfunction"|grep -v END
        if [  $? -eq 0 ]
        then
                echo $line |read fname
        else
                echo $line |tr -d " "|grep "callGlobalFunction1"  
                if [  $? -eq 0 ]
                then
                        echo "--------" $fname
                fi
        fi
        echo $line |tr -d " "|grep "ENDpublicfunction"
        if [  $? -eq 0 ]
        then
                fname=
        fi
done



---------- Post updated at 11:39 AM ---------- Previous update was at 09:04 AM ----------

Hi all,

My file is about more than 20000 lines. My script is taking somuch time to get required ouput. Is it possible to do bit faster.........? My code attached already.
# 7  
Old 07-16-2009
What OS, what awk version?
I said "Use gawk, nawk or /usr/xpg4/bin/awk on Solaris" ...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search for a word in column header that fully matches the word not partially in awk?

I have a multicolumn text file with header in the first row like this The headers are stored in an array called . which contains I want to search for each elements of this array from that multicolumn text file. And I am using this awk approach for ii in ${hdr} do gawk -vcol="$ii" -F... (1 Reply)
Discussion started by: Atta
1 Replies

2. Shell Programming and Scripting

Script to find string based on pattern and search for its corresponding rows in column

Experts, Need your support for this awk script. we have only one input file, all these column 1 and column 2 are in same file and have to do lookup for values in one file(column1 and column2) but output we need in another file Need to grep row whose string contains 9K from column 1. When found... (6 Replies)
Discussion started by: as7951
6 Replies

3. UNIX for Beginners Questions & Answers

Search for word in huge logfile and need to continue to print few lines from that line til find date

Guys i need an idea for one logic..in shell scripting am struggling with a logic...So the thing is... i need to search for a word in a huge log file and i need to continue to print few more lines from that line and the consecutive line has to end when it finds the line with date..because i know... (1 Reply)
Discussion started by: Prathi
1 Replies

4. Shell Programming and Scripting

Search for a specific word and print only the word from the input file

Hi, I have a sample file as shown below, I am looking for sed or any command which prints the complete word only from the input file. Ex: $ cat "sample.log" I am searching for a word which is present in this file We can do a pattern search using grep but I need to cut only the word which... (1 Reply)
Discussion started by: mohan_kumarcs
1 Replies

5. Shell Programming and Scripting

Search for the word and exporting 35 characters after that word using shell script?

I have a file input.txt which have loads of weird characters, html tags and useful materials. I want to display 35 characters after the word description excluding weird characters like $$#$#@$#@***$# and without html tags in the new file output.txt. Help me. Thanx in advance. My final goal is to... (11 Replies)
Discussion started by: sachit adhikari
11 Replies

6. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

7. Shell Programming and Scripting

bash script to find date based on search string for continuesly updating file

Hi All, I am very new to UNIX and I have tried this for a longtime now and unable to crack it.... There is a file that is continuously updating. I need to search for the string and find the date @ which it updated every day..... eg: String is "work started" The log entry is as below: ... (1 Reply)
Discussion started by: Nithz
1 Replies

8. UNIX for Dummies Questions & Answers

Find EXACT word in files, just the word: no prefix, no suffix, no 'similar', just the word

I have a file that has the words I want to find in other files (but lets say I just want to find my words in a single file). Those words are IDs, so if my word is ZZZ4, outputs like aaZZZ4, ZZZ4bb, aaZZZ4bb, ZZ4, ZZZ, ZyZ4, ZZZ4.8 (or anything like that) WON'T BE USEFUL. I need the whole word... (6 Replies)
Discussion started by: chicchan
6 Replies

9. UNIX for Dummies Questions & Answers

Using find command for timestamp based search

Hi, I am writing a script where i need to list all the files that have a scecific timestamp. I get this time stamp from another file. Is it possible to do this with 'find' command? Please let me know your valuable inputs. Thanks Sunny. (1 Reply)
Discussion started by: sunny_03
1 Replies

10. UNIX for Dummies Questions & Answers

search for hardlinks based on filename via find command

I am using command substitution into a find command in a script where I have built a menu to do a bunch of tasks within my unix account. When I choose the options for to find a file/files that have the same inode of the entered filename, ie hardlinks, nothing shows up. When I choose the appropiate... (2 Replies)
Discussion started by: hunternjb
2 Replies
Login or Register to Ask a Question