Skip to main content
added 38 characters in body
Source Link
gthm
  • 1.9k
  • 4
  • 27
  • 37

Its been asked several times but its not clear to me yet.

I have the following text in a file ( data.txt, tab delimeted ):

ABC 12 ABC-AS 14 DEF 18 DEF-AS 9 

Now I want to search for ABC and DEF, but not ABC-AS, DEF-AS as a result.

grep -w ABC data.txt 

Output:

grep -w ABC data.txt ABC ABC-AS grep --no-group-separator -w "ABC" data.txt ABC ABC-AS grep --group-separator="\t" -w "ABC" data.txt ABC ABC-AS 

Its been asked several times but its not clear to me yet.

I have the following text in a file ( data.txt ):

ABC ABC-AS DEF DEF-AS 

Now I want to search for ABC and DEF, but not ABC-AS, DEF-AS as a result.

grep -w ABC data.txt 

Output:

grep -w ABC data.txt ABC ABC-AS grep --no-group-separator -w "ABC" data.txt ABC ABC-AS grep --group-separator="\t" -w "ABC" data.txt ABC ABC-AS 

Its been asked several times but its not clear to me yet.

I have the following text in a file ( data.txt, tab delimeted ):

ABC 12 ABC-AS 14 DEF 18 DEF-AS 9 

Now I want to search for ABC and DEF, but not ABC-AS, DEF-AS as a result.

grep -w ABC data.txt 

Output:

grep -w ABC data.txt ABC ABC-AS grep --no-group-separator -w "ABC" data.txt ABC ABC-AS grep --group-separator="\t" -w "ABC" data.txt ABC ABC-AS 
Source Link
gthm
  • 1.9k
  • 4
  • 27
  • 37

How to handle "-" in grep?

Its been asked several times but its not clear to me yet.

I have the following text in a file ( data.txt ):

ABC ABC-AS DEF DEF-AS 

Now I want to search for ABC and DEF, but not ABC-AS, DEF-AS as a result.

grep -w ABC data.txt 

Output:

grep -w ABC data.txt ABC ABC-AS grep --no-group-separator -w "ABC" data.txt ABC ABC-AS grep --group-separator="\t" -w "ABC" data.txt ABC ABC-AS