Re: How do I search a file and return matching filenames?

Re: How do I search a file and return matching filenames?

am 18.12.2007 19:35:59 von Ed Morton

On 12/18/2007 7:44 AM, dawingz@gmail.com wrote:
> On Dec 18, 8:16 am, Loki Harfagr wrote:
>
>>Tue, 18 Dec 2007 05:04:48 -0800, dawingz did cat :
>>
>>
>>>I would like to parse a file and return a matching filename e.g. search
>>>abc.log and return all occurrences of *.txt. I want the filenames only
>>>not the entire matching line.
>>
>> Please define 'filename', if you can define it you will
>>probably not be very far to write the correct regexp that
>>will select and trim what you want.
>>
>>
>>>I haven't been able to find an example of
>>>this using either sed or grep. Any ideas will be appreciated.
>>
>> I'd suppose that it'd be easier in awk, feasible in sed
>>and very depending on your context with grep, now maybe
>>your def of 'filename' is very strict so that would be
>>easy in grep as well.
>
>
> The filenames are alphanumeric, it may contain lowercase and uppercase
> letters and numbers, no spaces or other special characters and always
> end with ".txt".
> e.g. sales100.txt, finance.txt

If your awk supports REs as RSs (e.g. GNU awk):

gawk -v RS='[^[:alnum:].]+' '/\.txt/' abc.log

Ed.