Reputation: 145
I have many text files in different sub directories, whereby each files has the file extension ".pro".
Each file contains of one or more lines where the text "PRO <name>
," or "Function <name>
," occurs.
After the <name>
follows a comma followed by variables.
I would like to generate a list consisting of 2 columns:
1st column: the full file name (with full path)
2nd column: "PRO <name>
" or/and "Function <name>
For the two example files/scripts below the resulting text would be:
<full path>read_scenes_out.pro PRO READ_SCENES_CLA
<full path>read_scenes_out.pro PRO PRO READ_TAU_IN
<full path>read_scenes_out.pro FUNCTION READ_HRIT
<full path>read_scenes_in.pro PRO READ_SCENES_FLG
<full path>read_scenes_in.pro PRO READ_SCENES_ELEV
<full path>read_scenes_in.pro PRO READ_TAU_IN
<full path>read_scenes_in.pro FUNCTION READ_HRIT2
Since I am a beginner with Linux I cannot solve this myself. The only small success was two find out how to list all full path's of pro files in all subdirectories:
find . | grep ".pro" | sort -z
May be this can be combined with that answer.
Two example files ("..." is a place holder for programming code):
file name 1 named "read_scenes_out.pro"
PRO READ_SCENES_CLA, ICLA, INDATE=INDATE
...
end
PRO READ_TAU_IN, TAU, INFILE=INFILE
...
end
FUNCTION READ_HRIT, slot, ChannelId, counts, pgm=pgm
...
end
file name 2 named "read_scenes_in.pro"
PRO READ_SCENES_FLG, NTEST, INDIR=INDIR, INDATE=INDATE
...
end
PRO READ_SCENES_ELEV, IELEV, INDIR=INDIR
...
end
PRO READ_TAU_IN, TAU, INFILE=INFILE
...
end
FUNCTION READ_HRIT2, slot, ChannelId, counts, pgm=pgm
...
end
Upvotes: 1
Views: 59
Reputation: 189387
Try something like
find . -name '*.pro' \
-exec grep -Eo '(PRO|FUNCTION)[ ]+[^ ,]+' /dev/null {} +
where the whitespace inside both character classes [...]
consists of a space and a tab.
The file name separator output by grep
is a colon; it should not be hard to change this by way of a simple sed
postprocessing step if it's important. Or maybe switch from grep
to Awk to have more control over how the output is generated.
Upvotes: 2