Regular expressions : match 2 file names
How can we do a simple match by regular expressions on two filenames. I plan to use it in the command 'find -regex'
Code:
hosts.txt |
-regex is not really required here as -name can still use globbing and apart from the .txt ending there are no other real similarities, hence:
Code:
find <path> -name '*.txt' |
Or you can strictly search only these two files:
Code:
find . \( -name hosts.txt -o -name ipaddress.txt \) |
If you really want to use the '-regex' option of find, then you can do it like this:
Code:
find . -regextype posix-extended -regex '.*/hosts\.txt|.*/ipaddress\.txt' Also remember that -regex works on the full path, not just the filename. colucix' -name version is probably easier though. |
Thanks to all.
I ended up using colucix's version with the -o operator. It was interesting to see the regex solution though. |
All times are GMT -5. The time now is 08:20 AM. |