Find the answer to your Linux question:
Results 1 to 8 of 8
i have to ask this question WITHOUT posting any of the file that i am trying to "grep" (as it contains confidential info) basically throughout the file, there exists instances ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41

    i need some help using grep in a fairly advanced way...


    i have to ask this question WITHOUT posting any of the file that i am trying to "grep" (as it contains confidential info)

    basically throughout the file, there exists instances of (email@somewhere.com)
    along with ALOT of other garbage i dont need....

    i just want to produce an output file containing nothing but one email on each line.... but getting all the emails out of the file WITHOUT getting the emails that are NOT in ()

    maybe something like:

    grep -w '(.*)' file??? OR
    grep -w '.com\|.@.' file???
    PLEASE help ... and btw how do you change a file type from data to ASCII??

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    but getting all the emails out of the file WITHOUT getting the emails that are NOT in ()
    Stated another way, you only want the emails that are in parens, que no?

    Let's take an example file called some-file. It contains:
    Code:
    encryptedstuff2349823423 c@domain.com (col@domain.com) encryptedstuff293843
    encryptedstuff3297983283 t@domain.com (tex@domain.com) encryptedstuff984372
    The following statement will get what you want:
    Code:
    grep -o '(.*@domain.com)' some-file

  3. #3
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Don't want parens in the output? Then use:
    Code:
    grep -o '(.*@domain.com)' some-file | tr -d '()'

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41
    thanks bunches!!
    but what if the domain varies with EACH email (and there are like 1000+)???
    Code:
    grep -o '(.*@.*.com)' some-file???

  6. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    P.S. If the email does not always have the same domain you could probably use something like
    Code:
    grep -o '(.*@.*\.com)' some-file | tr -d '()'
    Likewise, if it's not always a .com suffix you could use some form of wild carding there too.

  7. #6
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41
    ok i think i am beginning to understand grep a little better now

    .*@.*\.com = the \.com tells grep the next anticipated occurence should be

    at the beginning of the NEXT expression???

  8. #7
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    The \.com means: Escape the . and treat it literally. And treat com literally.

    Here is one more example for you:
    Code:
    dpecs@lnxvm3:~> grep -o '(.*@.*\..*)' some-file | tr -d '()'
    This takes anything in parens that follows the form something@something.something. Note that any of the "something" instances here can also be blank.

    Here is a short tutorial on regular expressions if you're interested: http://forums.suselinuxsupport.de/in...howtopic=23485

  9. #8
    Just Joined! herot's Avatar
    Join Date
    Dec 2005
    Posts
    41
    thank you very much again

    btw i was thinking of grep -w '\<bay' *

    that one does any word in any line that begins with bay....

    sorry i am very new to grep (its very powerful and i like it)

Posting Permissions

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