[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:29:15 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
On 11/02/2016 12:24 PM, Paul Jackson wrote:
> Greta asked:
>>> So what I have to add in grep command to put the limit of 30 characters?
>
> Eric replied:
>>> You can't do it with grep.
>
> Bruce suggested:
>>> cut -c 30 filename | grep ACGTAC
>
> Using the following grep command seems to work for me, and is about
> 40% faster, in terms of user CPU time spent, on my system, using a large
> dataset I have (some web server logs) than using cut and grep in a pipeline,
> as the extra CPU cost of the more complex grep expression is more than
> compensated for by the reduced copying of the datastream:
>
> grep -E '^.{0,30}GTGTCA
That searches up to 36 characters. If you want to limit it to just the
first 30, you need '^.{0,24}GTGTCA', since the match will never occur
later than the 24th character of the first 30.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature