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}VG}-2`E`:Ge^BnBT*%'!tLV`wX]qo2<1Q0cfv+=;UrWSj,2G-1j7z97Sy9aj93|M2X{|}mCNs[MZ^"Qs%Wt]CO/j?CyTlo]&>\6gxR^=S|c9.6G}y3m;32[j3e.0f\(pC9n9FN`LO;N)T$AXY"pLblBaA8ztKWIXGK#|6N?REvu%F53;G$3n:JJI7kx>Q9<h29}^CnvmO<!?=*9LI?|:L^Fd{=U8^f^`)ej@|D0Ifp`G(R5=Hx6z!T/'>d3pf^vD1zG@BN29d'i&`t$$
And I tested the existence of pattern "XYZ" with grep, sed, awk and Perl.
Time taken, in descending order is -
Code:
$
$
$ time perl -ne 'print if /XYZ/' testfile_22mb.txt 1>/dev/null
real 0m0.982s
user 0m0.015s
sys 0m0.015s
$
$ time sed -n '/XYZ/p' testfile_22mb.txt 1>/dev/null
real 0m0.771s
user 0m0.624s
sys 0m0.062s
$
$ time awk '/XYZ/' testfile_22mb.txt 1>/dev/null
real 0m0.300s
user 0m0.186s
sys 0m0.031s
$
$ time grep "XYZ" testfile_22mb.txt 1>/dev/null
real 0m0.152s
user 0m0.077s
sys 0m0.015s
$
$
A few microseconds less than if I had actually printed the results; each case matches and prints 31 lines.
So, not much difference if done once. But it will add up if you are doing this a gazillion times inside a loop.
tyler_durden
Last edited by durden_tyler; 09-13-2010 at 04:45 PM..
These 3 Users Gave Thanks to durden_tyler For This Post:
Hello, there.
I'm a new beginner to Linux kernel and curious about its memory management.
When multiple applications apply for memory space at the same time, how Linux kernel solve the resource contending problem for high performance?
I have known that there is a buddy system for allocating and... (4 Replies)
I've got this program set up so that it creates files whose unique names specify the jobs their contents describe. In order to retrieve the information inside those files, I have to do a "grep" and awk or sed to extract it. I've just assumed that making a directory with that unique name that... (1 Reply)
Hi !! I've finished an awk exercise. Here it is:
#!/bin/bash
function calcula
{
# Imprimimos el mayor tamaño de fichero
ls -l $1 | awk '
BEGIN {
max = $5; # Inicializamos la variable que nos guardará el máximo con el tamaño del primer archivo
}
{
if ($5 > max){ #... (8 Replies)
how efficient is it, and how practical is it to call outside programs in a shell script (bash) for small tasks?
for example, say i have a script that might preform many tasks, one of those tasks may require root access; rather than implementing inside the script a method to use su or sudo to... (11 Replies)