GNU bug report logs - #24858
URGENT: Question about grep

Previous Next

Package: grep;

Reported by: Greta <romano.greta <at> gmail.com>

Date: Wed, 2 Nov 2016 15:35:02 UTC

Severity: normal

Tags: notabug

Done: Eric Blake <eblake <at> redhat.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Greta <romano.greta <at> gmail.com>
Subject: bug#24858: closed (Re: bug#24858: URGENT: Question about grep)
Date: Wed, 02 Nov 2016 15:50:02 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#24858: URGENT: Question about grep

which was filed against the grep package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 24858 <at> debbugs.gnu.org.

-- 
24858: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=24858
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Eric Blake <eblake <at> redhat.com>
To: Greta <romano.greta <at> gmail.com>, 24858-done <at> debbugs.gnu.org
Subject: Re: bug#24858: URGENT: Question about grep
Date: Wed, 2 Nov 2016 10:49:30 -0500
[Message part 3 (text/plain, inline)]
tag 24858 notabug
thanks

On 11/02/2016 09:53 AM, Greta wrote:

> String to search: GTGTCA
> 
> File:
> 
>>HWI-ST740:1:C2GCJACXX:1:1101:1279:1825 1:N:0:
> _/NGACGCTCTGACCTTGGGGCTGGTCGGGG/__A_TGCTGAGGAGACGGTGACCAGGGTTCCCTGGCCCCACANNNCCAAGCTTCCNNNNNNNNNNNNNNNNNNN
> 
>>HWI-ST740:1:C2GCJACXX:1:1101:1349:1847 1:N:0:
> _/NTTAGATGAGGGAAACATCTGCATCAAGTT/__G_TTTATCTGTGACAACAAGTGTTGTTCCACTGCCAAAGAGTTTCTTATAATAAAACAATCGGGGTGGCACNNNNN
> 
> 
> I want that the research is done only in the underline characters.

Underlining doesn't show up in plain text mail (and we prefer plain text
over html bloat on the mailing list).  But I think your point still made
it across

>  So
> what I have to add in grep command to put the limit of 30 characters?

You can't do it with grep.  But you can do it with sed or awk.  Use the
right tool for the job at hand :)

Let's strip your example down to a smaller test case: I want to search
for a one-byte string '1', but only in the first 3 bytes of a file.
With grep, it is not possible; the pattern matches anywhere in the line:

$ printf '012000001\n345000001\n' | grep 1
012000001
345000001

But with sed, we can copy the entire line to hold space, truncate the
line in pattern space, then do the search; if successful, print the line
stored in hold space:

$ printf '012000001\n345000001\n' | \
  sed -n 'h; s/^\(.\{3\}\).*/\1/; /1/ { x;p }'
012000001

And I'll leave the awk program as an exercise for the reader.

Therefore, I'm tagging this as not a bug.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]
[Message part 5 (message/rfc822, inline)]
From: Greta <romano.greta <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: URGENT: Question about grep
Date: Wed, 2 Nov 2016 15:53:45 +0100
[Message part 6 (text/plain, inline)]
Dear grep developer,

I am Greta Romano and I need your help as soon as possibile.

I want to use grep command to search a string of 6 characters in every 
line of a file (biological file with DNA nucleotide).

The problem is that I need to search these 6 characters in the first 30 
characters of each line. I report you an example:

String to search: GTGTCA

File:

>HWI-ST740:1:C2GCJACXX:1:1101:1279:1825 1:N:0:
_/NGACGCTCTGACCTTGGGGCTGGTCGGGG/__A_TGCTGAGGAGACGGTGACCAGGGTTCCCTGGCCCCACANNNCCAAGCTTCCNNNNNNNNNNNNNNNNNNN
>HWI-ST740:1:C2GCJACXX:1:1101:1349:1847 1:N:0:
_/NTTAGATGAGGGAAACATCTGCATCAAGTT/__G_TTTATCTGTGACAACAAGTGTTGTTCCACTGCCAAAGAGTTTCTTATAATAAAACAATCGGGGTGGCACNNNNN

I want that the research is done only in the underline characters.  So 
what I have to add in grep command to put the limit of 30 characters?

Thank you very much

Best regards

Dr. Greta Romano

[Message part 7 (text/html, inline)]

This bug report was last modified 8 years and 255 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.