GNU bug report logs -
#24858
URGENT: Question about grep
Previous Next
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
Message #18 received at 24858 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
On 11/02/2016 10:52 AM, Bruce Dubbs wrote:
>>
>> 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?
>
> cut -c 30 filename | grep ACGTAC
That works if you are only interested in seeing the first 30 characters
of a given line, rather than printing the entire line when the match was
only within the first 30 characters. If you need to map back to the
entire line, you can use some sort of decorate-search-undecorate
algorithm to keep the search portion still under grep, but at that
point, it's probably easier to just write it all in a language that can
do it in a single pass.
I guess I should also mention that if you know your lines are a fixed
width (say for example that every line is exactly 80 characters), then
you can exploit that using just grep to find a match only in the first
30 characters by explicitly spelling out the fixed-width remainder of
the line as an anchor:
grep 'ACGTAC.*.\{50\}$' filename
Sadly, the two example lines you printed were not the same length, so I
don't think it helps for your case.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
This bug report was last modified 8 years and 254 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.