The Useless Use of Cat is not particularly slowing down the script by much; the main problem is that you are grepping the file over and over for each search string. Perhaps you could change it to grep for all the strings at the same time, then change the output into the format you want. A simple sed script should work for this.
This is just a proof of concept, and doesn't handle the case-insensitive searching you have in the original script. Other than that, it will find matching lines, and change them into the corresponding label; then count the number of occurrences of these labels in the resulting output.
Anyway, the point is, in order to speed it up, see if you can run only one pass over the log file, and end up with a much smaller amount of data which you could process further into the report you want.
This doesn't print anything at all for fields which are not found; if you want explicit zero counts, adding that as a post-processing stage should be a fairly trivial exercise.
Perhaps you would do well to separate the string and label data from the script itself. That's also left as an exercise.
Last edited by era; 08-07-2008 at 04:51 AM..
Reason: Oops, updated to also handle the check2 cases (I hope)
Hi,
I am new script programming, I have written a script shown velow to read username and passwd from /etc/security/passwd, i am able to read username, but unable to grep lastupdate. please look into the code and suggest if any changes need.
#!/bin/ksh
USERNAME=""
fname=/usr/bin/lastupdate... (1 Reply)
Hi,
I want to check whether a file of the format myfile_YYYYMMDD_HHMMSS.txt exists in a particular directory. Here YYYYMMDD_HHMMSS is the time stamp, so it will be numbers always .
What is the best method to do this
I did it like this :
ls myfile_*_*.txt
but it will list files... (1 Reply)
Hi
I have the following at the end of a service shutdown script used in part of an active-passive failover setup:
###
# Shutdown all primary Network Interfaces
# associated with failover
###
# get interface names based on IP's
# and shut them down to simulate loss of
# heartbeatd
... (1 Reply)
Hi
I am new to Unix/Linux
I know commands and shell scripts which are useful for my project.
But i need to know the basics and commands and shell scripts in detail and easy guide.
Please refer a book.
Thanks
Haripatn (6 Replies)
Hi!
I need to install a application from one server to several other servers. My script would copy the install-script to other machines and run it.Since it has to be non-interactive , just wondering if yum can be used for the same.
Please let me know , if you guys are aware of other... (1 Reply)
hi i need to get the values from an xml file like the <TAG> values and write to a file please suggest me the commands and some good reading material sites so that i can implement (1 Reply)
Pls review this code and provide your feedbacks to make it more efficient.I have tried to add to each section.
Code
###############################################################
#!/bin/ksh
RRSRC=/test
RREP=/test
#Directories
test_dir=/test
#Imp Files
FILENAME=/test/files.txt
#... (5 Replies)
i am jaswanth,
i am very new to unix/linux, upto now i worked in windows only., but i took coatching for unix.., and my sir teached all my classes in red hat linux and told me that all are same...!!!
I know shall programming in red hat linux..,
but now i installed opensloaris but the... (5 Replies)
Hi,
I'm a beginner and am learning c programming. I want to learn UNIX/LINUX in parallel. But I don't know difference between UNIX and LINUX and where they are applied in real life. As a beginner, some people asked me to start with UNIX. Please let me know some very good books for UNIX. Also a... (6 Replies)