bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#24858: URGENT: Question about grep


From: Eric Blake
Subject: bug#24858: URGENT: Question about grep
Date: Wed, 2 Nov 2016 12:00:21 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]