- 论坛徽章:
- 145
|
回复 17# abcfy2
the "time" command will tell you the answer
seq -f "xxx %g" 1000 > FILE
seq -f "pat1 %g" 10 >> FILE
seq -f "xxx %g" 980 >> FILE
seq -f "pat2 %g" 10 >> FILE
seq -f "xxx %g" 8000 >> FILE
wc -l FILE
time awk 'BEGIN{s=1000;e=2000;IGNORECASE=1}s<=NR&&(/pat1/||/pat2/){print NR":"$0}NR>=e{exit}' FILE
time sed -n '1000,2000{=;p}' FILE | sed '/^[0-9]\+$/{N; s/\n/\t/}' | grep -iE 'pat1|pat2'
----------------------
and I try them by three times on ubuntu 12.04.3 LTS
$ time awk 'BEGIN{s=1000;e=2000;IGNORECASE=1}s<=NR&&(/pat1/||/pat2/){print NR":"$0}NR>=e{exit}' FILE
1001:pat1 1
...
2000:pat2 10
real 0m0.044s <=== first
real 0m0.067s <=== second
real 0m0.069s <=== third
$ time sed -n '1000,2000{=;p}' FILE | sed '/^[0-9]\+$/{N; s/\n/\t/}' | grep -iE 'pat1|pat2'
1001 pat1 1
...
2000 pat2 10
real 0m0.167s <=== first
real 0m0.131s <=== second
real 0m0.100s <=== third
|
|