|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
VeriSign Code Signing Digital Certificates provides assurance to end users. Read about this and more in the free white paper: “How to Digitally Sign Downloadable Code for Secure Content Transfer.” Learn More! |
|
#1
|
|||
|
|||
|
Grep help
I am not sure if this is the right spot for this question, I am sorry if I got the wrong place.
I am trying to create a grep that will do the following: I have a file with a list of words, I am trying to create a grep to find all the words that (for example) have the letters A,B,C or D in it but no other letters. So it would return a list of words like CAB,DAB etc. but not BAT. Hope that makes sense. Any help would be appreciated. |
|
#2
|
|||
|
|||
|
Though not being the most elegant solution,
grep '[A-D][^a-zE-Z0-9][A-D]' filename(s) lists the lines with only the correct words but listing *only* the words and not the lines is sth else, if you're asking that.. |
|
#3
|
|||
|
|||
|
a sed approach:
first sed collect all strings containig ABCD the second delete all strings NOT containing ABCD sed -ne '/[ABCD]/p' inputfilename | sed -e '/[^ABCD]/d' if you use variables: GetIt=ABCD sed -ne "/[$GetIt]/p" inputfilename | sed -e "/[^$GetIt]/d" grep is sure able to do something similar, for this kind of jobs i prefer sed. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Grep help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|