I'm writing a script that at one point needs to check the contents of another script's log file to determine how to proceed. An example record from the log file is:
1.) the record contains "mcref", which is declared earlier in the script as $reffilepattern, and
2.) the record contains "060417", which is declared earlier in the script as $todayyymmdd.
I don't need to be picky about which fields contain the data, because the format is consistent. I'm presently doing this to read the entire line into the variable $loadedref:
Obviously, this works just fine, except that piping the results of one grep into another grep seems unholy. The log file is small, so while efficiency is not a concern at this point, it will be eventually as the log file grows. I tried to combine this into one grep that says, "give me the record that contains both "mcref" (without quotes) AND "060417" (with quotes), with any number of characters in between (including none)." I've tried goofy stuff like:
...which doesn't work. Can anyone give me some pointers here? I know I'm missing something really simple -- it's late in the day! Thanks in advance.
I think what you have is fine. If your worried about performace then I suggest going to PERL. Perl is much faster and better at parsing files. It's what perl was meant for.
I was going to write the script but I got tired and I'm going home. I'll check back tomorrow.
Interesting -- grep "${reffilepattern}.*${todayyymmdd}" $reflog works (I can't believe I didn't think of that), but on a larger test file (about 60MB) it is actually 2 to 3 times slower than the original method of piping one grep through another. I'm guessing because the first grep narrows the records down for the second grep. I guess I'll just keep my original method. Thanks for the help, though. This is good to know!
I have one array SPLNO with approx 10k numbers.Now i want to search the subscriber number from MDN.TXT file (containing approx 1.5 lac record)from the array.if subscriber number found in array it will perform below operation.my issue is that it's taking more time because for one number it's search... (6 Replies)
is there a way to efficiently monitor logfiles that do not have a date or time format? i have several logs on several different servers that need to be monitored. but i realized writing a script for this would be very complex and time consuming giving the variety of things i need to check for i.e.... (2 Replies)
Hi,
I was hoping someone could suggest an alternative to code I currently have as mine takes up far too much processor time and it to slow.
The situation:
I have a programme that runs on some files just before they are zipped up and archived, the program appends a one line summary of the... (4 Replies)
Hi,
I am trying to populate an array with data from a text file. I have a working method using awk but it is too slow and inefficent. See below.
The text file has 70,000 lines. As awk is a line editor it reads each line of the file until it gets to the required line and then processes it.... (3 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Write a template main.c file via shell script to make it easier for yourself later.
The issue here isn't writing... (2 Replies)
I am having a file, around 500 lines. which contains one letter words, two letters words,...and so on(up to 15 letter words and words are not seprated by line). I need to compare all 1 letter words with 3,4,5 and 6 letters word, all 2 letters words with 2,3,4 and 5 letters words and all 3 letters... (3 Replies)
Hi Experts,
I've been trying simple grep to search for a string in a huge number of files in a directory.
grep <pattern> *
this gives the search results as well as the following -
grep: <filename>: Permission denied
grep: <filename>: Permission denied
for files which I don't have... (4 Replies)
I've done quite a bit of searching on this but cannot seem to find exactly what I'm looking for. Say I have a | delimited input file with 6 columns and I need to change the value of a few columns and create an output file. With my limited knowledge I can do this with many lines of code but want... (5 Replies)
I need to put together a RAID1 file server for use by Windoze systems. I've built zillions of windows systems from components. I was a HPUX SE for a long time at HP, but have been out of the game for years.
I've got an old workhorse mobo FIC PA-2013 with a 450 MHz K6 III+ I could use, but I'd... (2 Replies)
I have a script which searches a huge log file for the existence of a specified string and if the string is not present i receive an alert mail.
Here's an extract:
STRING=$(grep 'warning' logfile | tail -1 | wc -l)
if (( ${STRING} > 0 ));
then
print -- "---- Warning etc.... (3 Replies)