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.
- 12-02-2005 #1
i need some help using grep in a fairly advanced way...
basically throughout the file, there exists instances of (email@example.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??
- 12-02-2005 #2but getting all the emails out of the file WITHOUT getting the emails that are NOT in ()
Let's take an example file called some-file. It contains:Code:
encryptedstuff2349823423 firstname.lastname@example.org (email@example.com) encryptedstuff293843 encryptedstuff3297983283 firstname.lastname@example.org (email@example.com) encryptedstuff984372Code:
grep -o '(.*@domain.com)' some-file
- 12-02-2005 #3
Don't want parens in the output? Then use:Code:
grep -o '(.*@domain.com)' some-file | tr -d '()'
- 12-02-2005 #4
but what if the domain varies with EACH email (and there are like 1000+)???Code:
grep -o '(.*@.*.com)' some-file???
- 12-02-2005 #5
P.S. If the email does not always have the same domain you could probably use something likeCode:
grep -o '(.*@.*\.com)' some-file | tr -d '()'
- 12-02-2005 #6
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???
- 12-02-2005 #7
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 '()'
Here is a short tutorial on regular expressions if you're interested: http://forums.suselinuxsupport.de/in...howtopic=23485
- 12-02-2005 #8
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)