Searching for files and phrases in files.
Last updated: Aug17,2020

I have a ton of html files, ASCII help files, and various image files that document software and other procdures. Here are some trick for searching through all of that stuff.

Primary List
  1. Finding different types of files.
  2. Find strings with grep.
  3. A useful example of searching.



Finding different types of files.

The unix "find" utility is extremely useful.


% find /home/sco/scohtm/scocodes -name "*.png" -print > list.png_files 
% linecnt list.png_files 
*** This is really fast, and it finds 593 png files!!!!!! Holy shit.

% find /home/sco -name "*.fits" -print > list.fits_files
% linecnt list.fits_files 
 20005
*** Again, super fast and it finds >2000 images! 
 
Return to top of page.



Find strings with grep.

The strings that are contained iside files is done with the "grep" command.


To list files (just once) that contain a phrase:
% grep -rl 'fits images' /home/sco/scohtm/scocodes |tee -a SEARCH 
 *** SEARCH contains 14 lines

To list files (just once) that contain a phrase using a case-insensitive search: 
% grep -ril 'fits images' /home/sco/scohtm/scocodes |tee -a SEARCH 
 *** SEARCH contains 88 lines

To list all files/lines that contain a phrase:
% grep -r 'fits images' /home/sco/scohtm/scocodes |tee -a SEARCH 
 *** SEARCH contains 15 lines

To list all files/lines that contain a phrase using a case-insensitive search:
% grep -ri 'fits images' /home/sco/scohtm/scocodes |tee -a SEARCH 
 *** SEARCH contains 122 lines

 
These examples are nice, but sometimes searches like this can produce huge files. For instance, in the example above I used the phrase "fits" as part of the search. When I use the case-insensitive approach I get large listings that involve FITS images, soemthing I have written about a lot. Becasue grep is so very fats, I have written a scripts that runs all 4 of the cases above for a search directory and string set. It reports some cursory numbers to the user. This way you can quickly surmise which lits to look at first. You might also decide to use a new tesxt string in the search to narrow down the file listings. An easy way to do this is to use txts (TeXT Search).
Return to top of page.


A useful example of searching.

Suppose I wanted to know about the phrase "acm bias"?

 

WEB SEARCH EXAMPLE: 

% txts $scohtm/scocodes "acm bias" 
 0  Number of files with the text phrase                                   =  30 
 1  Number of files with the text phrase using case-insentive search       =  35 
 2  Number of files/line with the text phrase search                       =  79 
 3  Number of files/line with the text phrase using case-insentive search  =  84 

I read trhough the most extensive file (SEARCH3) and I still can not 
find what I am looking for. Ica look at the figures in all of the html 
docs using the following steps. 

% uhpwg.sh SEARCH0   

Number of unique paths found =   18

The number of images file located =  84
View them with:    display_image_list uhpwg.out_images  

So I run the suggested command: 
% display_image_list uhpwg.out_images


In this example, I viewed 84 images in just a few minutes.




Back to SCO code page