In short : I have several log files and I need to find the last file with a certain keyword in it.
Through Internet I found a way to examine the last, the previous and the previous previous file, but for some reason cannot determine the name of the file before that.
My purpose is to find the begin date & time and the end date & time.
The end time is always in the last file, but the begin time can be the last 4 files.
Because of the number of log files, I need to go from newest to oldest.
I will post my code so far in the next posting.
Greetings,
E.J.
---------- Post updated at 10:49 AM ---------- Previous update was at 10:38 AM ----------
Here the code.
Perhaps not the best you may have seen, but it almost serves it purpose.
Line 109 is where I need help.
You can copy&paste it to try it out.
But of course when there are better solutions I would like to hear them too.
Always nice to learn something.
I am on a Solaris 10 machine with ksh88 (not allowed to upgrade it).
Here the result:
---------- Post updated at 04:04 PM ---------- Previous update was at 10:49 AM ----------
Okay, I was clearly on the wrong track.
There is an easier way to go through a list of files.
This is what works for me in order to find the begin date & time.
Probably it can be made even more compact, but I am served.
Not sure I understand your request.
So - the end time will be in the last file (key word END), and the begin (keyword BEGIN) will be in the same file or in four predecessors. Why not loop up to five times through ls -t LOG_hostx* (watch out, no -r option!), grepping each file for "BEGIN"? If there's more than one BEGIN and you need the last one, try tacing the files.
[SOLVED] - [ksh] finding last file with keyword in it
Quote:
Originally Posted by RudiC
Not sure I understand your request.
So - the end time will be in the last file (key word END), and the begin (keyword BEGIN) will be in the same file or in four predecessors. Why not loop up to five times through ls -t LOG_hostx* (watch out, no -r option!), grepping each file for "BEGIN"? If there's more than one BEGIN and you need the last one, try tacing the files.
Indeed, this was the solution, I was on the wrong track.
That happens when you are expanding the code, or when you adapt the code to little changes.
In my case, first the BEGIN/END sequence was in the last file only, then spread over 2 files, then over 3 and currently over 4.
So I kept looking for the next file, not paying attention to a sound solution.
Now it can be in any file, so is future proof.
Thanks for responding.
I am trying to create an output file new that contains only the S5-00580 lines from list that are not in analysis_log. My attempt to do this is below.
The new file would be used in the aria2c command to download only new folders. The aria2c command works to download all the files in list, but... (7 Replies)
Hi Everyone,
Need help in extracting the hostname from the below output.
Expected output:
DS-TESTB-GDS-1.TEST.ABC.COM
DS-TESTB-GDS-2.TEST.ABC.COM
....
...
/tmp $ cat -n /tmp/patchreport
1 /usr/bin/perl /admin/bin/patch/applyPatches.pl --apply_patches... (4 Replies)
Hi
I want to implement something like this:
if( keyword1 exists)
then
check if(keyword2 exists in the same line)
then replace keyword 2 with New_Keyword
else
Add New_Keyword at the end of line
end if
eg:
Check for Keyword JUNGLE and add/replace... (7 Replies)
Hi,
I've to find the file which has the pattern
"Delete Report for History Tables"
and need to search this file pattern from directory which has sub directories as well.
I'm using ksh 88
Please suggest me which command will be used to find the file pattern .
Thanks. (1 Reply)
Hi Guys,
I need to read a file until I find a blank line. and in the next iteration I want to continue reading from the line I find a keyword.
For ex: my file looks like
PDS_JOB_ALIAS
CRITERIA_ITEM_TYPE
PDS_JOB_CRITERIA_ITEM
CRITERIA_ITEM_TYPE
First I want to read the file... (2 Replies)
Hi,
I have a file which got only one column and got some keywords. I have another file where the keywords used in the first file are repeated in the second file.
Now I would like to know how many times each keyword from the first file is repeated in the second file.
Request your help on... (1 Reply)
It saves me lot of typing and space/lines when I do not use full 'if' keyword and construct, instead use ..
&& <statement> || <statement>
that perfectly replaces..
if ; then
<statement>
else
<statement>
fi
Can I use following syntax when I want to add multiple statements under 'if'... (4 Replies)
I am trying to find for the pattern in first 5 bytes of every line in a text file and then generate a new file with the pattern found.
Example: expected pattern is '-' to be serached in first 5 bytes of file only.
Input File
ab-cd jan-09
ddddd jan09
cc-ww jan09
dsgdq jan-09
... (2 Replies)
hi guys i have a problem here, im trying to stablish a relationship between a text file and an input user for example the script is going to prompt the user for some football team and what the script is going to do is return the colums in which that input is located so far this is what i have ... (6 Replies)