0

I need to extract the names of functions defined in a C source file given as parameter to the script. I'm not very familiar to PowerShell but shouldn't be something like this:

If ($FileExists -eq $True)
{
     select-string $args[0] -pattern "\(void\|double\|char\|int\) \.*(.*)"
}
1
  • I shouldn't have escaped the characters so-> select-string $args[0] -pattern "(void|double|char|int) \.*(.*)" works but how can I refer the name of the function only (something like linux-sed would be useful) Commented Apr 22, 2012 at 20:59

1 Answer 1

2

I'd define the list of file extensions that you want to search in and use them in the Include parameter, then pipe to select-string and extract the capturing group matches.

dir -Path C:\c-program -Include *.h, *.c -Recurse | Select-String -Pattern '(void|double|char|int) (\w+)\(' | % {$_.Matches[0].Groups[2].Value}

Here's a canned example using function names from wikipedia:

'void incInt(int *y)','int main(int argc, char* args[])','int subtract(int x, int y)' | Select-String -Pattern '(void|double|char|int) (\w+)\(' | % {$_.Matches[0].Groups[2].Value}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.