It is currently Thu, 20 Jan 2022 10:02:40 GMT

Author Message
 searching through multiple files
Hi all
a common need when using "vi" or "less" is to extend a
search pattern ( /pattern ) through multiple files.
That is, if I open multiple files:

$ vi *.log
$ less *.log

then I I'd like that the search, once bottom is reached, goes through next
Is it possible to do it ?

 Fri, 08 Sep 2006 19:49:32 GMT   
 searching through multiple files
Hi Francesco,

you may use a loop like

for F in *.log
   grep -n "searchtext" "$F" && (echo "$F"; echo "")



 Fri, 08 Sep 2006 20:28:48 GMT   
 searching through multiple files

"Stefan Lagotzki" <> ha scritto nel messaggio
Thanks for your answer. Anyway I'd like to know if it's possible to do
the search from vi/less.....hope I'm not OT here...

 Fri, 08 Sep 2006 21:21:04 GMT   
 searching through multiple files
In article <gpA7c.85926$>,

I will focus on less (vi is similar, but complicated by the fact that it
circles around).  When you reach the end of one file, do :n to get to the
next file, then n to search again.

Or, if you really need it to be seamless, you can do:

    cat *.log | less

 Fri, 08 Sep 2006 21:26:39 GMT   
 searching through multiple files


man less reveals:

      ^E or *
           Search multiple files.  That is, if the search reaches the END of
           the current file without finding a match, the search continues in
           the next file in the command line list.

so /searchtext will find occurrences in the current open file, but
/*searchtext will find it in all opened files.

Your mother has a smooth forehead!
- Klingon insult.

 Fri, 08 Sep 2006 21:36:09 GMT   
 searching through multiple files

"Brian" <> ha scritto nel messaggio

Thanks a lot

 Sat, 09 Sep 2006 17:17:10 GMT   
   [ 6 post ] 

Similar Threads

1. grep-like search with multiple file output?

2. search and replace multiple html files

3. Search and Replace on Multiple Files?

4. search and replace in multiple files

5. Multiple file search and replace

6. Searching Multiple directories for a data file

7. Search-and-replace on multiple files

8. searching files for multiple text targets

9. Search & Replace in multiple files

10. global text search replace on multiple files

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software