I think the request was "How to grepthis function?", i.e. function A. So a small adaption of nezabudka's fine script might be suited for this:
Aside, @cmdcmd: "Not work " doesn't really help analyse your code and find possible errors. Post facts: error messages, exit codes, undesired vs. desired output
Let's say I have a file written in C programming
How to grep this function?
I tried
Not work
Moderator's Comments:
Please use CODE tags on all sample input, output, and code segments; not just on shell code segments.
Hi cmdcmd,
Please be a little more verbose on what you are trying to do.
Are you trying to find the definition of the function named A in you C source file? If so, does it need to include the type of the value returned by the function? Do you want the complete function definition or just the part from function up to and including the first opening brace ({) character?
Are you trying to find all calls to the function named A in your C source file?
The code you provided can't work if you are trying to find the function definition in your C source file because the ERE you're using won't match the <space>s before and after the name of your function.
Assuming that you're using a GNU grep utility (which I don't have available to verify my suggestion) you might come closer to what you were trying to do with:
assuming that you're just looking for the text on a line starting with function for the function declaration for the function named A, the function prototype (not including the return code) fits on a single line, that the next line contains the opening brace for the function definition, and that you don't care about the return type of this function.
Just saying that something does not work isn't really helpful. We need to know what doesn't work; what diagnostic were produced, if any; what output it produced; what additional output you wanted; what output it produced that you did not want.
This User Gave Thanks to Don Cragun For This Post:
I want to find c function definition with pattern with shell script by checking condition for each line:
data_type
functionname(param_list){
....
}
I knew cscope or ctag is usable for this task, but if there any ways to do without using them.
I am thinking of checking line condition... (3 Replies)
Hi all,
I'm bit new to the advanced bash shell scripting.
When I'm looking at some of the existing code in my organization, got confused with a few variable definings.
For ex:
var1={1:-30}
var2="abc def ghi"
var3={xyz:-$var2}
In above, 1st and last lines are confusing me.... (4 Replies)
Hi
Here is the problem ( Exercise 3-3, Using The Shell of The Unix Programming Environment, Kerninghan, Pike, 3rd edition ):
Predict what each of the following grep commands will do, and then verify your understanding.
grep \$
grep \\$
grep \\\$
grep '\$'
grep '\'$'
grep \\
grep \\\\... (3 Replies)
How can I recursively find all files in a directory and print out the file and first line number of any text blocks that match the below cases?
This would seem to involve find, xargs, *grep, regex, etc.
In summary, I want to find so-called empty "try-catch blocks" that do not contain code... (0 Replies)
Hi,
im working on an assignment (airline ticketing system). im kinda having problems with the search function. i want users to be able to search by departure time or by flight. however, my output displays the whole chunk of data instead of what they are supposedly searching for. appreciate if... (1 Reply)
Hi all ,
I'm new to unix
I have a checked project , there exists a file called xxx.config .
now my task is to find all the files in the checked out project which references to this xxx.config file.
how do i use grep or find command . (2 Replies)
Hi,
I am having list of C function names say
function1
function2
function3
and i am having many source files under my current directory.
Now i would like to find the file names which contains the function definition from my list.
It would be appreciable if... (1 Reply)
Hello All,
I have another Korn shell question. I am writing a script that will ftp a file from my production database to my test database.
To this, I have to construct a loop that checks a specified folder for a file.
If the file exists, I want it execute the ftp protocol and then exit. ... (2 Replies)
Could someone please direct me to a link that gives the definitions for each of the letters from the results of the $- environment variable? It would be nice to know what shell options each of the letters represents, but I am specifically looking for the shell option for 'c' (lowercase c). Thank... (12 Replies)
Hello,
I am trying to learn Networking Programming in C in unix enviorment. I want to know how good it is to become a network programmer. i am crazy about Network programming but i also want to opt for the best carreer options. Anybody experienced Network Programmer, please tell me is my... (5 Replies)