but I don't like it - too complex for a simple alias I can carry with me in different environments I deal with. And I am not sure awk is available everywhere. Any bash/sed based ideas?
To search all header files in the current directory in either of your two specified formats, the following will work with either ed or ex with any shell that accepts basic Bourne shell syntax (including any POSIX conforming shell such as bash and ksh ):
#!/bin/ksh
for i in *.h
do ed -s "$i" <<-EOF
g/^[ ]*struct[ ][ ]*$1[ ]*{/ .,/^};/p
g/^}[ ]*$1[ ]*;/ ?typedef[ ][ ]*struct[ ]*{?,.p
EOF
done
Note that there is a single <tab> character before the EOF on the next to the last line. It will not work correctly if this tab is changed to spaces. Note also that in the here-document there is a single <space> character and a single <tab> character between each pair of square brackets ( [ and ] ).
With the sample a.h and b.h headers given in post #1 in this thread, if the above script is saved in a file named tester and it is made executable:
chmod +x tester
then the command:
./tester Rec3
produces the output:
struct Rec3 {
int f1;
float k1;
float k2;
};
typedef struct {
int f1;
float k1;
float k2;
}Rec3;