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
or
$ less *.log

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



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

you may use a loop like

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

Stefan

.



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

"Stefan Lagotzki" <lag...@gmx.de> ha scritto nel messaggio
news:c3mm9a$2et$02$1@news.t-online.com...
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...
Regards
Francesco



 Fri, 08 Sep 2006 21:21:04 GMT   
 searching through multiple files
In article <gpA7c.85926$FJ6.3159...@twister1.libero.it>,

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

[snips]

man less reveals:

/pattern
[snips]
      ^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.

B.
--
Your mother has a smooth forehead!
- Klingon insult.



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

"Brian" <nos...@my-local.net> ha scritto nel messaggio
news:c3mq49$c2e$1$8302bc10@news.demon.co.uk...

Thanks a lot
Francesco



 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