Extract function names and directories from php files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract function names and directories from php files
# 1  
Old 06-20-2012
Extract function names and directories from php files

I need a script that extracts function names from php files together with their location (path and file in which they are defined).

The php files are located in several directories under a base directory.

Ideally the output should be something like:

"Path/FileName/FunctionName" for a function "FunctionName" which is defined in file "FileName.php" and FileName.php is located in Path.

Should be pretty simple, but I haven't done any scripting for years, so hopefully somebody can help. Any scripting language is fine.
# 2  
Old 06-20-2012
Code:
find /path/to/folder -name '*.php' |
        xargs egrep -o 'function[ \t][ \t]*[a-zA-Z_]*'

Prints lines like
Code:
/home/mec/public_html/noweb/navbar.php:function rowclass

# 3  
Old 06-20-2012
Perfect! Thanks a lot.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract filepath names between two strings

OS : Fedora Linux 26 Shell : bash I have a file with around 5000 lines like below. file /usr/share/icons/Papirus/16x16/actions/papirus-icon-theme-20180501-1.noarch conflicts with file ... file /usr/share/icons/Papirus/16x16/actions/align-horizontal-left-to-anchor.svg conflicts between... (7 Replies)
Discussion started by: John K
7 Replies

2. Shell Programming and Scripting

Compare files with different names in different directories

Hi, I have a requirement to compare files in different directories with different names. The files have a datestamp in their name (It might not be a sequential datetimestamp). This is for Redhat Linux. I have more than 5 directories and more than 10 file in each directory to be compared. ... (4 Replies)
Discussion started by: GosarJunk
4 Replies

3. Shell Programming and Scripting

Want to remove directories names 1 2 3 ...

Dear All, I have some list of directories names 1 2 3 .... n. Number can vary each time when I run some software to create these folders. When ever I wanted to run new case I have to remove all the sub-directories named 1 2 3 4 .... in case directory. How can I do it using rm -r command? ... (4 Replies)
Discussion started by: linuxUser_
4 Replies

4. Shell Programming and Scripting

Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (4 Replies)
Discussion started by: shadow_fawkes
4 Replies

5. Shell Programming and Scripting

**URGENT ** : Comparing the pattern of the file names in 2 different directories

Hi, I have got a requirement for which i need your help. The following problem is required to get solved in PERL SCRIPT. Here is the requirement. There are 4 folders say SRC_DIR1, SRC_DIR2 and TGT_DIR_1,TGT_DIR_2 (Note: both path of SRC_DIR1 & SRC_DIR2 are different but both path of... (1 Reply)
Discussion started by: shadow_fawkes
1 Replies

6. UNIX for Dummies Questions & Answers

Creating named directories from a list of names

Hi There, I'm a competent computer user that is learning basic unix commands. This is a slightly hypothetical question (for now at least!) but I can see a need for doing something like this in the near future. So I recently learned this command mkdir foo{1..100} which of course create's... (4 Replies)
Discussion started by: lookslikejames
4 Replies

7. Solaris

How to extract files from a tar file without creating the directories?

Hello all. I have a tar file that contains a number of files that are stored in different directories. If I extract this tar file with -xvf , the directories get created. Is there a way to extract all of the files into one directory without creating the directories stored in the tar file. (9 Replies)
Discussion started by: gkb
9 Replies

8. Shell Programming and Scripting

script to find function names

hi, i am a newbie and have to write a rather complicated script. Assume that i have a variable called x and a C source code file say file1.c (these are the inputs of the script) and i need to find the names of all the functions in the C file containing x.Take the following code as an example: ... (2 Replies)
Discussion started by: samantha grace
2 Replies

9. Shell Programming and Scripting

Compare File Names in Different Directories...

I do not know much about shell scripting and need to create a script and I am at a loss. If someone can help me, that would be great!! I have two directories: /dir1 /dir2 I need to get the sequence number which is part of the filename in /dir1 and delete all files in /dir2 that are... (4 Replies)
Discussion started by: stky13
4 Replies
Login or Register to Ask a Question