|
Home > Archive > Unix Shell > February 2007 > help with find.... file extension - regexp???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
help with find.... file extension - regexp???
|
|
| Martin Jørgensen 2007-02-19, 1:16 pm |
| Hi,
I don't know if this has something to do with regular expressions. I
tried to google for something but couldn't come up with a solution.
I want to find all files with either extension .c, .h or .cpp.
I tried:
find . -name "*.([ch]|cpp)"
But it doesn't work... How do I make it work? It is also best if it
does a case-insensitive search for those extensions...
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
| |
| Stephan Grein 2007-02-19, 1:16 pm |
| Martin Jørgensen wrote:
> Hi,
>
> I don't know if this has something to do with regular expressions. I
> tried to google for something but couldn't come up with a solution.
>
> I want to find all files with either extension .c, .h or .cpp.
>
> I tried:
>
> find . -name "*.([ch]|cpp)"
>
> But it doesn't work... How do I make it work? It is also best if it
> does a case-insensitive search for those extensions...
>
>
> Best regards
> Martin Jørgensen
>
find . -iregex ".*?\(cpp\|c\|h\)"
That one?
--
Stephan Grein, <stephan at stephan minus rockt dot de>
https://stephan-rockt.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
| |
| Stephane CHAZELAS 2007-02-19, 1:16 pm |
| 2007-02-19, 17:04(+01), Stephan Grein:
[...]
>
> find . -iregex ".*?\(cpp\|c\|h\)"
>
> That one?
That would have been OK on comp.gnu.shell, but on
comp.unix.shell, it would rather be:
find . \( -name '*.[cChH]' -o
-name '*.[cC][pP][pP]' \) -type f -print
Or (assuming no file path contains any newline character):
find . -type f -print | grep -Ei '\.([ch]|cpp)$'
--
Stéphane
| |
| Martin Jørgensen 2007-02-19, 1:16 pm |
| >>>>> "Stephane" == Stephane CHAZELAS <this.address@is.invalid> writes:
Stephane> 2007-02-19, 17:04(+01), Stephan Grein: [...][vbcol=seagreen]
> find . -iregex ".*?\(cpp\|c\|h\)"
Hmmm... Nothing happens... Are you sure this is the right syntax (not
that I know about it)?
Stephane> That would have been OK on comp.gnu.shell, but on
Stephane> comp.unix.shell, it would rather be:
Stephane> find . \( -name '*.[cChH]' -o -name '*.[cC][pP][pP]' \)
Stephane> -type f -print
What's the difference between those groups? I like the shorter
version...
Stephane> Or (assuming no file path contains any newline
Stephane> character):
Stephane> find . -type f -print | grep -Ei '\.([ch]|cpp)$'
You finding all files and grepping them... File paths with newline
characters? I've heard about file paths with spaces and such, but
newline characters??? Why would somebody make a path with such one?
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
| |
| Stephane CHAZELAS 2007-02-19, 7:15 pm |
| 2007-02-19, 19:46(+01), Martin Jørgensen:
[...]
>
> Hmmm... Nothing happens... Are you sure this is the right syntax (not
> that I know about it)?
If that's a GNU find, it should be -iregex '.*\.\(cpp\|[ch]\)'
>
> Stephane> That would have been OK on comp.gnu.shell, but on
> Stephane> comp.unix.shell, it would rather be:
>
> Stephane> find . \( -name '*.[cChH]' -o -name '*.[cC][pP][pP]' \)
> Stephane> -type f -print
>
> What's the difference between those groups? I like the shorter
> version...
One is standard, one (-iregex) is GNU specific.
>
> Stephane> Or (assuming no file path contains any newline
> Stephane> character):
>
> Stephane> find . -type f -print | grep -Ei '\.([ch]|cpp)$'
>
> You finding all files and grepping them... File paths with newline
> characters? I've heard about file paths with spaces and such, but
> newline characters??? Why would somebody make a path with such one?
[...]
Why wouldn't one do?
What about :
mv 0001.jpg 'Summer holidays.
Sunbathing on the beach.
No to little wind.
A little over-exposed
..jpg'
A would definitely advice against using those newline characters
in filenames, but nothing prevents anyone to do so.
--
Stéphane
| |
| Martin Jørgensen 2007-02-20, 7:18 am |
| >>>>> "Stephane" == Stephane CHAZELAS <this.address@is.invalid> writes:
Stephane> 2007-02-19, 19:46(+01), Martin Jørgensen: [...][vbcol=seagreen]
Stephane> If that's a GNU find, it should be -iregex
Stephane> '.*\.\(cpp\|[ch]\)'
Doesn't work... I'm on mac os X... That's unix, right? And linux is
gnu, right?
I typed:
$ find . -iregex '.*\.\(cpp\|[ch]\)'
$ find . -name "*.cpp"
../main.cpp
../output_energy.cpp
How come there's not even a warning/error message? The syntax must be
allright, then... But perhaps mac os X interprets that expression
differently?
Stephane> That would have been OK on comp.gnu.shell, but on
Stephane> comp.unix.shell, it would rather be:[vbcol=seagreen]
Stephane> find . \( -name '*.[cChH]' -o -name '*.[cC][pP][pP]' \)
Stephane> -type f -print[vbcol=seagreen]
Stephane> One is standard, one (-iregex) is GNU specific.
Ok.
Stephane> Or (assuming no file path contains any newline
Stephane> character):[vbcol=seagreen]
Stephane> find . -type f -print | grep -Ei '\.([ch]|cpp)$'[vbcol=seagreen]
Stephane> [...]
Stephane> Why wouldn't one do?
Stephane> What about :
Stephane> mv 0001.jpg 'Summer holidays. Sunbathing on the beach.
Stephane> No to little wind. A little over-exposed .jpg'
Stephane> A would definitely advice against using those newline
Stephane> characters in filenames, but nothing prevents anyone to
Stephane> do so.
Ok.
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
| |
| Stephane CHAZELAS 2007-02-20, 7:16 pm |
| 2007-02-20, 09:46(+01), Martin Jørgensen:
>
> Stephane> 2007-02-19, 19:46(+01), Martin Jørgensen: [...]
>
> Stephane> If that's a GNU find, it should be -iregex
> Stephane> '.*\.\(cpp\|[ch]\)'
>
> Doesn't work... I'm on mac os X... That's unix, right? And linux is
> gnu, right?
MacOS/X decends from some BSD which is one family of Unix, and
GNU is not Unix though it may be considered as a family of Unix
as well.
Linux is not GNU, Linux is Linux, some (most) Linux
distributions include Linux (the kernel) plus a lot of the GNU
tools and the GNU C library, plus other non-GNU applications
(that may use GNU libraries and have generally been compiled by
GNU tools, but that can be said of many other systems as well).
> I typed:
>
> $ find . -iregex '.*\.\(cpp\|[ch]\)'
> $ find . -name "*.cpp"
> ./main.cpp
> ./output_energy.cpp
>
> How come there's not even a warning/error message? The syntax must be
> allright, then... But perhaps mac os X interprets that expression
> differently?
[...]
You'd have some kind of BSD find. A lot of the GNU find features
can also be found in BSD. But as it's a different find
implementation, the features may be implemented differently
(that's where standards help).
On BSD/MacOS, -iregex might expect a basic or extended regular
expression (while find's -iregex expects a GNU basic regular
expression).
From FreeBSD's man page it would seem that you need:
find -E . -iregex '.*\.(cpp|[ch])'
--
Stéphane
| |
| Martin Jørgensen 2007-02-21, 1:23 am |
| >>>>> "Stephane" == Stephane CHAZELAS <this.address@is.invalid> writes:
Stephane> 2007-02-20, 09:46(+01), Martin Jørgensen:
-snip-[vbcol=seagreen]
Stephane> [...]
Stephane> You'd have some kind of BSD find. A lot of the GNU find
Stephane> features can also be found in BSD. But as it's a
Stephane> different find implementation, the features may be
Stephane> implemented differently (that's where standards help).
Stephane> On BSD/MacOS, -iregex might expect a basic or extended
Stephane> regular expression (while find's -iregex expects a GNU
Stephane> basic regular expression).
Stephane> From FreeBSD's man page it would seem that you need:
Stephane> find -E . -iregex '.*\.(cpp|[ch])'
Oh, thanks. I think I'll have to learn how to use reg-expr's some
days...
Best regards
Martin Jørgensen
--
---------------------------------------------------------------------------
Home of Martin Jørgensen - http://www.martinjoergensen.dk
|
|
|
|
|