LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Select only words with a letter (http://www.linuxquestions.org/questions/linux-newbie-8/select-only-words-with-a-letter-566558/)

Coimbra 07-04-2007 07:47 AM

Select only words with a letter
 
Hi,

Can I select only words with the letter "a" for example? On a file txt.

example:

cat expre.txt | grep........

regards

dxqcanada 07-04-2007 07:57 AM

Grep will give you the entire line if it encounters a match.

Do you just want the specific word only that has an "a" in it?

Coimbra 07-04-2007 08:02 AM

yeap,

I only want words with letters "a".

I know than the documentos only has words with letters "a" and "b".

Coimbra 07-04-2007 08:05 AM

The document is similar to:

aaa
abbabba
aaaabba
aba
aab
bba
baab
..
..
..
..

b0uncer 07-04-2007 08:28 AM

Umm if you mean there are only words that consist of either a, b or both of them, and you want to print lines with only 'a's (which means: you don't want to print lines that have 'b's in them)? In that case:

Code:

grep -v b file.txt
Actually I'm not sure if "b" or "file.txt" comes first; I always forget it. Well, try and see :)

EDIT: the above works if there's one word per one line. If there are multiple, it will not work.

Coimbra 07-04-2007 08:39 AM

PERFECT!!!!!!!!!!!


I have to use the next command:

cat [name_fichero] | grep -v b

It's perfect

ghostdog74 07-04-2007 09:45 AM

Quote:

Originally Posted by Coimbra
PERFECT!!!!!!!!!!!


I have to use the next command:

cat [name_fichero] | grep -v b

It's perfect

Code:

grep -v b name_fichero


All times are GMT -5. The time now is 05:27 AM.