Find the answer to your Linux question:
Results 1 to 5 of 5
hi, I am trying to find a phrase inside a bounce of documents inside a specific folder. Is there any program (like a text editor) or a unix command so ...
  1. #1
    Just Joined! maxpayne_gr's Avatar
    Join Date
    Nov 2006
    Posts
    33

    program or unix command that finds patern on documents of a folder?

    hi,

    I am trying to find a phrase inside a bounce of documents inside a specific folder.
    Is there any program (like a text editor) or a unix command so I can retrieve every document that contains the specific phrase inside that folder?

    Thanx in advance

  2. #2
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,413
    If all the files are in plain text, and you're looking for the phrase "my_phrase", the following might be what you need,
    Code:
    find ./ | xargs grep my_phrase
    This will search every file in the current folder, and every folder beneath it, for files containing the string "my_phrase".

    Let us know if that helps.
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  3. #3
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by smolloy View Post
    If all the files are in plain text, and you're looking for the phrase "my_phrase", the following might be what you need,
    Code:
    find ./ | xargs grep my_phrase
    This will search every file in the current folder, and every folder beneath it, for files containing the string "my_phrase".

    Let us know if that helps.
    Wouldn't this be just the same that this?

    Code:
    grep -r <string> /path/to/search/*

  4. #4
    Linux Guru smolloy's Avatar
    Join Date
    Apr 2005
    Location
    CA, but from N.Ireland
    Posts
    2,413
    Quote Originally Posted by i92guboj View Post
    Wouldn't this be just the same that this?

    Code:
    grep -r <string> /path/to/search/*
    Well, you learn something every day, don't you!

    I don't know why I never thought of searching grep's man page to find the recursive option -- I've always just piped "find" into it instead.

    Thanks for correcting me.
    Registered Linux user #388328 || Registered LFS user #15880
    AMD 64 X2 4600+ :: 2X1GB DDR2 800 :: GeForce 9400 GT 512MB :: ASUS M2N32 Deluxe :: 4X250GB SATAII
    Need instant help? Try us on IRC -- #linuxforums on freenode

  5. #5
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    No problem.

    Your approach is *mostly* correct, though a bit more complicated. It has one problem though: if the argument list get too big it will fail.

    In that, case, you *must* use grep -r, or if you like the pipe approach, use a while loop to read all the values:

    find ./ | while read file; do grep <string> "$file"; done
    This should work always, regardless of the number of files being listed by 'find'.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...