Help! "grep" doesn't work for me!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help! "grep" doesn't work for me!
# 1  
Old 02-14-2009
Error Help! "grep" doesn't work for me!

totally pis*ed off.
I have a data set (xxx.txt), as follows:

chr1 3821 rs127372 A/C 0.823
chr1 3822 rs127376 A/C/G 0.899
chr1 3722 rs612634 A/C 9.22
chr1 3262 rs7152 A/T 0.22
chr1 3711 rs737 A/C/G 0.2323
.......

I only want to get those lines with "A/C" (Exact match only!!)
therefore, I use:
grep -w A/C xxx.txt
however, the results really bother me! not only 'A/C', but also those lines with "A/C/G" or 'A/C/*' appear in my new file.
I don't know what's wrong with that. 'grep' used to work well for me.
Anyone knows?? thanks!!


PS: another question. if use "grep -w" to get exact match, what's the delimiter?? "\t" or " "? or even "/" is considered delimiter?? can I define it by myself?? Thanks again!

Last edited by kaixinsjtu; 02-14-2009 at 04:23 AM..
# 2  
Old 02-14-2009
Quote:
Originally Posted by kaixinsjtu
totally pis*ed off.
I have a data set (xxx.txt), as follows:

chr1 3821 rs127372 A/C 0.823
chr1 3822 rs127376 A/C/G 0.899
chr1 3722 rs612634 A/C 9.22
chr1 3262 rs7152 A/T 0.22
chr1 3711 rs737 A/C/G 0.2323
.......

I only want to get those lines with "A/C" (Exact match only!!)
therefore, I use:
grep -w A/C xxx.txt
however, the results really bother me! not only 'A/C', but also those lines with "A/C/G" or 'A/C/*' appear in my new file.
I don't know what's wrong with that. 'grep' used to work well for me.
Anyone knows?? thanks!!
How about
grep "A/C " xxx.txt
? there is a space after "C"
# 3  
Old 02-14-2009
I have tried, but failed to work. nothing show up after I put in a space after A/C.
I guess "/" is considered a 'space'...
That's also why I'm asking if I could set the delimiter by myself...

Quote:
Originally Posted by sunny651
How about
grep "A/C " xxx.txt
? there is a space after "C"
# 4  
Old 02-14-2009
Quote:
Originally Posted by kaixinsjtu
I have tried, but failed to work. nothing show up after I put in a space after A/C.
I guess "/" is considered a 'space'...
That's also why I'm asking if I could set the delimiter by myself...
en, this is what i have run on my machine (FC9)
Code:
-bash-3.00$ cat xxx.txt
chr1 3821 rs127372 A/C 0.823
chr1 3822 rs127376 A/C/G 0.899
chr1 3722 rs612634 A/C 9.22
chr1 3262 rs7152 A/T 0.22
chr1 3711 rs737 A/C/G 0.2323
-bash-3.00$ grep "A/C " xxx.txt
chr1 3821 rs127372 A/C 0.823
chr1 3722 rs612634 A/C 9.22
-bash-3.00$

I used
Code:
grep "A/C " xxx.txt

,rather than
Code:
grep -w "A/C " xxx.txt

# 5  
Old 02-14-2009
Yes I tried : grep "A/C " xxx.txt | more (with a space)
still nothing showed up!! Really sucks, why it didn't work on my computer! Gonna figure it out... maybe because of the format of the file??
driven me crazy... SmilieSmilieSmilieSmilieSmilieSmilie

Quote:
Originally Posted by sunny651
en, this is what i have run on my machine (FC9)
Code:
-bash-3.00$ cat xxx.txt
chr1 3821 rs127372 A/C 0.823
chr1 3822 rs127376 A/C/G 0.899
chr1 3722 rs612634 A/C 9.22
chr1 3262 rs7152 A/T 0.22
chr1 3711 rs737 A/C/G 0.2323
-bash-3.00$ grep "A/C " xxx.txt
chr1 3821 rs127372 A/C 0.823
chr1 3722 rs612634 A/C 9.22
-bash-3.00$

I used
Code:
grep "A/C " xxx.txt

,rather than
Code:
grep -w "A/C " xxx.txt

# 6  
Old 02-14-2009
Code:
-bash-3.00$ grep --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

-bash-3.00$
-bash-3.00$ whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz
-bash-3.00$ ldd /bin/grep
        libpcre.so.0 => /lib/libpcre.so.0 (0x00b17000)
        libc.so.6 => /lib/tls/libc.so.6 (0x009c1000)
        /lib/ld-linux.so.2 (0x009a8000)
-bash-3.00$
-bash-3.00$ cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant)
-bash-3.00$ bash --version
GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.
-bash-3.00$

That is my grep version.
You can upload your xxx.txt file if possible for us to test, or check the format of that file.

Smilie I am sorry that my computer is Red Hat Enterprise Linux AS release 4. not FC9. I mistaken it...

Be patien.
# 7  
Old 02-15-2009
I really appreciate your help!
However, the file is from human genome sequencing (>1G, too large).
I found some other way to do it. Not with Unix. But in R. Although not so efficient.
Anyway, thanks again. Smilie

Quote:
Originally Posted by sunny651
Code:
-bash-3.00$ grep --version
grep (GNU grep) 2.5.1
 
Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
-bash-3.00$
-bash-3.00$ whereis grep
grep: /bin/grep /usr/share/man/man1/grep.1.gz /usr/share/man/man1p/grep.1p.gz
-bash-3.00$ ldd /bin/grep
        libpcre.so.0 => /lib/libpcre.so.0 (0x00b17000)
        libc.so.6 => /lib/tls/libc.so.6 (0x009c1000)
        /lib/ld-linux.so.2 (0x009a8000)
-bash-3.00$
-bash-3.00$ cat /etc/redhat-release
Red Hat Enterprise Linux AS release 4 (Nahant)
-bash-3.00$ bash --version
GNU bash, version 3.00.15(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.
-bash-3.00$

That is my grep version.
You can upload your xxx.txt file if possible for us to test, or check the format of that file.

Smilie I am sorry that my computer is Red Hat Enterprise Linux AS release 4. not FC9. I mistaken it...

Be patien.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script: "mkdir -p" doesn't work with var(cat x)

Hello, :) I've an issue with the creation of a directory, All work without it :mad: So, below, my scripts with the debug output : #!/bin/bash # PATHS HOME_BACKUP="/home/backup" HOME_SCRIPT="/home/scripts/test/backup_server" TARGET="/var/www" # DATE DATE_Ymd=$(date +%Y-%m-%d) #... (1 Reply)
Discussion started by: Arnaudh78
1 Replies

2. Shell Programming and Scripting

Why doesn't "grep -w" ALWAYS work?

Working with IP addresses is a pain... Here's my problem: I'm putting some interface information to a file: 3.185.201.2 | Tu1102 152.162.54.130 | Gi0/2.36 3.185.226.2 | Gi0/1 3.185.0.82 | Tu1 ... (12 Replies)
Discussion started by: turk22
12 Replies

3. AIX

AIX 5.3 on p275 - "|" key doesn't work (!)

More issues. The "|" key doesn't work at all, either in the text terminal or in mwm (which starts fine when I do "startx"). How am I supposed to troubleshoot without a "|" key? (2 Replies)
Discussion started by: smithfarm
2 Replies

4. AIX

"/" doesn't work on command prompt for searching commands last typed

When I use "/" to look for a particular command that I typed in the current session it says D02:-/home/user1/temp> /job ksh: /job: not found. D02:-/home/user1/temp> previously it used to fetch all the commands which had job in it.. for example subjob, endjob, joblist etc... may I... (7 Replies)
Discussion started by: meetzap
7 Replies

5. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

6. UNIX for Advanced & Expert Users

sometimes "ps -elf" command doesn't work

when i give "ps -elf" or "ps" system gets hung. if i press "^c" come out from it... pls help..what should i do to get it resolved. thanks CKanth (4 Replies)
Discussion started by: srikanthus2002
4 Replies

7. Linux

By angle-brackets/"pipe" button doesn't work?

How can I configure it? I have a swedish keyboard with swedish keyboard setting. Everything works perfectly (едц) except that button. What can be wrong? /Richard ++ NOTE: It seems like the computer notices the input but that the button isn't assigned to anything (the keyboard-cursor stops).... (1 Reply)
Discussion started by: riwa
1 Replies

8. UNIX for Dummies Questions & Answers

Why "@z=$x+$y" doesn't work?

253 lab2-36:~/try_direct/another> set x=1;set y=2;@z=$x+$y @z=1+2: Command not found. 254 lab2-36:~/try_direct/another> (11 Replies)
Discussion started by: endeavour1985
11 Replies

9. Shell Programming and Scripting

my "case" doesn't work !

I'm using the case statement in the following script and it always takes the "*" default choice while it should be "3". I wonder why ??? dt_auj=`date +%d` NBLOG=`ls -al /users/notes01/LOG/t*|awk '{print $7}'|grep $dt_auj|wc -l` case $NBLOG in 1) cat ~/LOG/console-notes > $fic_tmp1 ;; 2)... (5 Replies)
Discussion started by: Nicol
5 Replies
Login or Register to Ask a Question