Question: (Closed) Using "grep" to count a string
0
gravatar for chchl7
3.7 years ago by
chchl730
United States
chchl730 wrote:

I counted a string "Chr" in a .TXT file using grep -c "Chr" <file.txt>. However, got a number much smaller than the real number. Can anybody help me out with this? Thank you!

snp sequence next-gen • 1.0k views
ADD COMMENTlink modified 3.7 years ago • written 3.7 years ago by chchl730
1

I think (not sure) grep give you the number of rows with "Chr" in it. So if you have two "Chr" in one row, it will count only as one.

ADD REPLYlink written 3.7 years ago by Maxime Lamontagne2.1k
1

Check spelling, try without the case-sensitive search, and see if there is a newline issue. Also, an example of your text file would be helpful to see what you are trying to match.

ADD REPLYlink modified 3.7 years ago • written 3.7 years ago by SES8.1k

also try this.

grep -o chr file.vcf | wc -w
ADD REPLYlink written 3.7 years ago by venu6.0k

There is no spelling or case issue? What is the newline issue, please?

ADD REPLYlink written 3.7 years ago by chchl730

Hello,

Thank you very much for your reply. I checked spelling, tried case-sensitive search, and found only one "Chr" in one row. I tried all comands kindly provided here, but still could not get the right number. By the way, what is the newline issue?

ADD REPLYlink written 3.7 years ago by chchl730
1

newline issue: https://en.wikipedia.org/wiki/Newline#Common_problems

tr -d "\r" < file.TXT | grep -c Chr
ADD REPLYlink written 3.7 years ago by Pierre Lindenbaum118k

What do you mean, the right number?  grep doesn't make mistakes. It's going to find how many lines have "Chr" in them. What do you want it to do instead?  Give an example of the data file please. 

ADD REPLYlink written 3.7 years ago by karl.stamm3.4k

Hello chchl7!

This isn't a bioinformatics question so this post does not fit the main topic of this site.  There are other sites that deal with questions like this, http://superuser.com springs to mind.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

Also, please don't post additional comments as answers to your question, use the top level comments if responding to someone who has commented, rather than answered the question.

ADD REPLYlink modified 3.7 years ago • written 3.7 years ago by Daniel Swan13k
Please log in to add an answer.
The thread is closed. No new answers may be added.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1258 users visited in the last hour