Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can i search a word called "Onderh"? Advanced search i would like to do such as: starting line with "Onderh" or line contain "Onderh".

Note: Local Backup directory, contain every days a snapshot of MySQL "database.sql (file size: 81902272)". Inside that file i need to apply the search.

[me@www win]$ ls
2011-03-01  2011-03-04  2011-03-07  2011-03-10  2011-03-13  2011-03-16  2011-03-19  2011-03-22  2011-03-25  2011-03-28  2011-03-31  2011-04-03  2011-04-06
2011-03-02  2011-03-05  2011-03-08  2011-03-11  2011-03-14  2011-03-17  2011-03-20  2011-03-23  2011-03-26  2011-03-29  2011-04-01  2011-04-04  2011-04-07
2011-03-03  2011-03-06  2011-03-09  2011-03-12  2011-03-15  2011-03-18  2011-03-21  2011-03-24  2011-03-27  2011-03-30  2011-04-02  2011-04-05  2011-04-08

[me@www 2011-04-08]$ ll
total 80092
-rw-r--r--  1 root root 81902272 Apr  8 01:00 database.sql
drwxr-xr-x 99 root root    12288 Apr  8 01:00 etc
drwxr-xr-x  4 root root     4096 Apr  8 01:00 home
drwxr-xr-x 10 root root     4096 Apr  8 01:00 html
drwxr-xr-x 14 root root     4096 Apr  8 01:00 postfixadmin-2.3
share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you want to check across all of those directories, try:

[me@www win]$ grep -n ^Onderh */database.sql

to find lines (the -n flag shows line number) starting with Onderh. The ^ is a special character to anchor the match to the start of the line - get rid of it if you want to find it anywhere in the line.

Ack could also be worth looking into if you have more complicated requirements. For example if the sql files you were interested in weren't so well organised, ack would be able to search within only .sql files in an entire directory structure.

share|improve this answer
    
Very nice "Ack", it highlights even while search found and matches. Didn't knew it was so smart. thanks –  YumYumYum Apr 8 '11 at 11:24

If the files are text files you can use grep with regex flag.

grep -R -E "^Onderh" *
grep -R "Onderh" *

First will search for line beginning with onderh, second for all lines containing it.

share|improve this answer
    
-E is for extended regular expressions. Grep without -E understands ^ because that ispart of ordinary regular expressions. I mainly use egrep (grep -E) if I need alternatives (e.g. grep -E "Ond(er|yz)h") –  RedGrittyBrick Apr 8 '11 at 9:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.