Grep -w not printing exact matches


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep -w not printing exact matches
# 1  
Old 07-07-2015
Grep -w not printing exact matches

Dear All,

Here is my input

Code:
TAACGCACTTGCGGCCCCGGGATAAAAAAAAAAAAAAAAAAAAATGGATT
NAGAGGGACGGCCGGGGGCATAAAAAAAAAAAAAAAAAAAAAGGGATTTC
NGGGTTTTAAGCAGGAGGTGTCAAAAAAAAAAAAAAAAAAAAAGGGATTT
NTGGAACCTGGCGCTAGACCAAAAAAAAAAAAAAAAAAAATGGATTTTTG
ATACTTACCTGGCAGGGGAGATACCATGATCAATAAAAAAAAAAAAAAAA
NACAAAGCATCGCGAAGGCCCGCGGCAAAAAAAAAAAAAAAAAATGGGAT

When I try this command
Code:
cat 1 | grep AAAAAAAAAAAAAAAAAAAAA

I get this output

Code:
TAACGCACTTGCGGCCCCGGGATAAAAAAAAAAAAAAAAAAAAATGGATT
NAGAGGGACGGCCGGGGGCATAAAAAAAAAAAAAAAAAAAAAGGGATTTC
NGGGTTTTAAGCAGGAGGTGTCAAAAAAAAAAAAAAAAAAAAAGGGATTT

But when I try

Code:
cat 1 | grep -w "AAAAAAAAAAAAAAAAAAAAA"

I get nothing in my output. I would like to search for exact strings in a file with more than 6 million lines.

Please comment.
# 2  
Old 07-07-2015
Your first attempt was an exact match already. Every line you got contained the string "AAAAAAAAAAAAAAAAAAAAA".
# 3  
Old 07-07-2015
You get nothing because you're asking for an exact word match i.e. the word "AAAAAAAAAAAAAAAAAAAAA"

Yet, there's no word as such in your example.

Let's say your looking for the word "ULTIMATE" in file 1 in a string like :
AAAAAAAAAAJJJJJJJJJJJJJDDDDDDDDDDDULTIMATEDDDDDDDDDDDDJJJJJJJ

Code:
grep ULTIMATE 1

Will give you the following output :
Code:
AAAAAAAAAAJJJJJJJJJJJJJDDDDDDDDDDDULTIMATEDDDDDDDDDDDDJJJJJJJ

While

Code:
grep -w "ULTIMATE" 1

Will give you nothing as no such word exists...

Then again if you had the following string in file 1 : AAAAAAAAAAJJJJJJJJJJJJJDDDDDDDDDDD ULTIMATE DDDDDDDDDDDDJJJJJJJ

Both
Code:
grep ULTIMATE 1

and
Code:
grep -w "ULTIMATE" 1

would give you the same output, that is :

Code:
AAAAAAAAAAJJJJJJJJJJJJJDDDDDDDDDDD ULTIMATE DDDDDDDDDDDDJJJJJJJ


Last edited by vincent72; 07-07-2015 at 07:20 PM..
# 4  
Old 07-08-2015
You probably want
Code:
grep "[^A]AAAAAAAAAAAAAAAAAAAAA[^A]" 1

?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep or sed - printing line only with exact match

Hello. In my script, some command return : q | kernel-default | package | 3.19.0-1.1.g8a7d5f9 | x86_64 | openSUSE-13.2-Kernel_stable_standard | kernel-default | package | 3.19.0-1.1.g8a7d5f9 | i586 | openSUSE-13.2-Kernel_stable_standard | kernel-default ... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

Help in printing n number of lines if a search string matches in a file

Hi I have below script which is used to grep specific errors and if error string matches send an email alert. Script is working fine , however , i wish to print next 10 lines of the string match to get the details of error in the email alert Current code:- #!/bin/bash tail -Fn0 --retry... (2 Replies)
Discussion started by: neha0785
2 Replies

3. Shell Programming and Scripting

Perl : printing the files in the exact order as it is..

Hi folks, I am trying to open directory and then print the files in that directory in PERL. I have used the below code. opendir(DIR,$destination) or die ("Cannot open directory $destination"); my @bwfiles = readdir(DIR); print @bwfiles; I am able to retrieve all the files the files... (2 Replies)
Discussion started by: scriptscript
2 Replies

4. Shell Programming and Scripting

Exact expression matches (can't seem to solve this)

I've seen dozens of similar threads but none seem to match what I'm looking for and I can't seem to make sense of how to do this so any help would be immensely appreciated. I am running a command that generates this output: Mike Smith Mike Smith Alaska Mike Smith Washington Mike Smith Alaska... (6 Replies)
Discussion started by: valgrom
6 Replies

5. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

6. Shell Programming and Scripting

Changing exact matches with awk from subfields

To give you some context of my issue the following is some sample dummy data. The field delimiter is "<-->". The 4th field is going to be tags for my notes. The tags should always be unique and sorted alphabetically. 1<-->01/20/12<-->01/20/12<-->1st note<-->1st note<-NL->2 lines... (4 Replies)
Discussion started by: adamreiswig
4 Replies

7. Shell Programming and Scripting

Using grep returns partial matches, I need to get an exact match or nothing

I’m trying to modify someone perl script to fix a bug. The piece of code checks that the zone name you want to add is unique. However, when the code runs, it finds a partial match using grep, and decides it already exists, so the “create” command exits. $cstatus = `${ZADM} list -vic | grep... (3 Replies)
Discussion started by: TKD
3 Replies

8. Shell Programming and Scripting

Printing between 2 matches with Perl

Can we please modify this perl one-liner to print lines between pattern1 and pattern2 in a file? Currently it prints lines till pattern2. (4 Replies)
Discussion started by: anand_bh
4 Replies

9. UNIX for Dummies Questions & Answers

| help | unix | grep - Can I use grep to return a string with exactly n matches?

Hello, I looking to use grep to return a string with exactly n matches. I'm building off this: ls -aLl /bin | grep '^.\{9\}x' | tr -s ' ' -rwxr-xr-x 1 root root 632816 Nov 25 2008 vi -rwxr-xr-x 1 root root 632816 Nov 25 2008 view -rwxr-xr-x 1 root root 16008 May 25 2008... (7 Replies)
Discussion started by: MykC
7 Replies
Login or Register to Ask a Question