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

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to