Time taken to run grep in different OS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Time taken to run grep in different OS
# 1  
Old 07-23-2013
Time taken to run grep in different OS

Hi ,

I am greping a keyword in all sql files in Solaris and Linux.

Solaris
Code:
 
bash-3.00$  time grep -iwc BEN_STARTUP_LERS_TL084701_WHO *.sql
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
real    0m0.640s
user    0m0.564s
sys     0m0.077s

Linux
Code:
 
[Sql]$ time grep -iwc BEN_STARTUP_LERS_TL084701_WHO *.sql
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
Load__v20130719-prod.sql:0
real    0m2.518s
user    0m2.499s
sys     0m0.013s

If you see in solaris it is taking less than one second where as in linux it is taking more than 2 sec to execute the same command.

Infact my aim is to reduce the time taken by this command as less as possible may be a littile fraction of a second because i have around 50k keywords to search..

Can anyone please advice how to reduce the execution time.
# 2  
Old 07-23-2013
if you are trying to search for fixed strings, you can use fgrep which is more faster than grep.
fgrep (grep -F in linux) is fixed or fast grep and behaves as grep but does not recognise any regular expression metacharacters as being special.
# 3  
Old 07-23-2013
Ensure a non-UTF locale
Code:
LC_ALL=C grep ...

# 4  
Old 07-23-2013
OS is a factor, as is filesystem, amount of free memory (esp. for Linux's read ahead ), I recommend faster disk storage or flash drives if you want to read files faster Smilie
grep is a pretty optimised command as it is...

Edit: Actually, on the locale issue, make sure "LC_COLLATE=Posix" if you're using ranges in grep.
# 5  
Old 07-23-2013
Quote:
Originally Posted by Skrynesaver
OS is a factor, as is filesystem, amount of free memory (esp. for Linux's read ahead ), I recommend faster disk storage or flash drives if you want to read files faster Smilie
grep is a pretty optimised command as it is...

Edit: Actually, on the locale issue, make sure "LC_COLLATE=Posix" if you're using ranges in grep.
Case matters in locale names. The POSIX Locale is all caps. Furthermore, on systems that conform to the IEEE's and ISO's POSIX Standards or The Open Group's Single UNIX Specifications, the C Locale and the POSIX Locale are identical. So LC_COLLATE=C and LC_COLLATE=POSIX have exactly the same effect. LC_COLLATE=Posix might have the same effect, might yield an error, or might be a completely different locale on some systems; but it has no defined meaning in the standards.

On systems that conform to the C standard but neither the POSIX Standards nor the Single UNIX Specifications, the requirements for the C Locale are not as stringent and there is no definition for, nor any requirement that there even be, a POSIX Locale.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitute grep command at run time

HI I am trying to use the following code in the shell script (using grep) usage() { echo "Usage: ./$0 <file name> <interval> <pattern>" } METRICS_FILE=$1 INTERVAL=$2 PATTERN="$3" .. if then PATTERN="grep Gx" fi COUNT=`cat ${METRICS_FILE} | "${PATTERN}" |egrep... (8 Replies)
Discussion started by: asifansari
8 Replies

2. Shell Programming and Scripting

Can we run tail -f for a specified time?

Hi all, I want to check a log file that gets updated very frequently, almost every second. What I want to do from a script is to check this log file 1) for a particular string 2) for a specified time while it is getting updated. And as soon as it finds that particular string the command... (4 Replies)
Discussion started by: pat_pramod
4 Replies

3. Solaris

Java Run Time

I have installed IBM Java Runtime V1.4.2 in solaris. but when i give java -version, it gets me this:java version "1.5.0_20" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_20-b02) Java HotSpot(TM) Client VM (build 1.5.0_20-b02, mixed mode, sharing) can you please tell me how do i... (3 Replies)
Discussion started by: ichwaiznicht
3 Replies

4. AIX

time of a particular command run

Hello all, I need to find, what time a particular command was run in one of our AIX box. In our environment, we use 'powerbroker' to login as root and there are so many people who use this. I tried history command, which shown me similar to below: 406 ls -l | *user* 407 ls -l... (1 Reply)
Discussion started by: gsabarinath
1 Replies

5. Programming

Run time Debugging

We have recently downloaded, installed and compiled gcc-3.0.4 code. gcc compiler has built successfully and we where able to compile some same test cpp file. I would like to know how we can modify gcc source code so that we add additional run time debugging statements like the binary in execution... (4 Replies)
Discussion started by: uunniixx
4 Replies

6. Shell Programming and Scripting

last run time of any script

how to find when last time a scrit has ran? (7 Replies)
Discussion started by: RahulJoshi
7 Replies

7. Shell Programming and Scripting

Run several commands at a time

Hello guys, I am new at shell scripting and I want to create a script that runs several commands at a time, ie: uptime, w, df -h and so on and send the output of this commands to a text file so it can be send via email at a certain time using crontab. Any help will be much appreciated! (4 Replies)
Discussion started by: agasamapetilon
4 Replies

8. Shell Programming and Scripting

run script for given time

Hi! I need to run my script for a specific number of time, as specified by the user: For instance, if the user specified 10, my script should run for until 10 seconds expire. How do I do this? (0 Replies)
Discussion started by: looza
0 Replies

9. Shell Programming and Scripting

Run script at same time

Hi My five script run throgh crontab at same time at 6 clock. Due to problem in the data load .Now I want to check time of load finish run these jobs. I create a script which check the load finish time but I have no idea how I run these JObs. This is very urget to me. Please reply me as soon... (3 Replies)
Discussion started by: Jamil Qadir
3 Replies

10. UNIX for Advanced & Expert Users

run script in autosys at a specified time.

I have created a shell script. I want to run the script in Autosys. Please note my shell script runs as "$ ksh run.ksh" How do I make autosys run this script at 5:00PM every day? insert_job: abc job_type: c box_name: run.box command: ksh run.ksh machine: mach1 #owner: mach1@mymach... (1 Reply)
Discussion started by: gram77
1 Replies
Login or Register to Ask a Question