You are not logged in.

#1 2025-04-02 16:38:06

dakota
Member
Registered: 2016-05-20
Posts: 417

[SOLVED] Recommended Approach to Extract Text from Multiple Files

Please recommend an approach to the following problem.

I have a directory of perhaps 100 html files. I want to seach through those files and print a list of file names and line number where specific text can be found.

I have very little experience with scripting, but would like to learn, and this looks like a fun place to start.

I'm not looking for a script, but rather a recommendation for the correct tool for the job. I know you can do this with dozens of different approaches but I don't want to read a dozen different books just to find the correct path. So, I hoping someone get nudge me in the correct direction.

This sounds like it might be something that sed is good at. Maybe create a list of file names in a directory, then  loop through the list  and use sed with regex? Or is there a better approach?

Cheers,

Edit - added context.

I do not need to parse the html. I'm just looking for specific text strings, but maybe multiple strings on the same line. Using grep (as suggested my mpan) seems like a very simple approach. (I had no idea grep could look in multiple files with a single command.)

Last edited by dakota (2025-04-02 17:49:49)


"Before Enlightenment chop wood, carry water. After Enlightenment chop wood, carry water." -- Zen proverb

Offline

#2 2025-04-02 17:18:33

mpan
Member
Registered: 2012-08-01
Posts: 1,593
Website

Re: [SOLVED] Recommended Approach to Extract Text from Multiple Files

Since no details or constraints have been provided, only “searching for text” and not “parsing HTML”:

grep -Fir 'text to find' directory_with_files

Paperclips in avatars? | Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#3 2025-04-02 17:49:33

dakota
Member
Registered: 2016-05-20
Posts: 417

Re: [SOLVED] Recommended Approach to Extract Text from Multiple Files

Well.

That was pretty trivial. I had no idea grep could look in multiple files with the same command. 

Cheers,


"Before Enlightenment chop wood, carry water. After Enlightenment chop wood, carry water." -- Zen proverb

Offline

Board footer

Powered by FluxBB