But how can I display the value side by side, I am getting the data from a logfile when the job starts and job ends.
[...]
Any hint please ?
This is actually quite easy, you just need to think things through first. Lets go back to your original file:
Of this file you only need the lines containing "STATUS: STARTING" and some ending notification. This could perhaps be "STATUS: SUCCESS", but somehow i don't believe that all jobs end that way - what other possible ending codes do you have, because your script will need to cover them too.
Let us go on, assuming for the moment that the only endng condition is "SUCCESS", this can be corrected later.
Next we make up some "rules" what to do with the respective lines, because at some point we need to read our input line by line:
- When we encounter a "STARTING" line we need to remember two things, the job name and the timestamp.
- When we encounter a "SUCCESS"-line we need to read also two things: the job name and the timestamp. But we don't need to store ("remember") them: the job name should be searched in our list of remembered (=started) jobs. If it is found, the stored starting time, the end time and the job name is printed.
The last point begs two questions: what are we going to do if we encounter a job with a start but no end? And what are we going to do with jobs with an end but no start?
Here is the skeleton of a shell script that implements what i said above. Neither is it very clever nor very mature, its intention to make it obvious how to implement common reasing like above into code. It also won't take the raised questions into account and implicitly assume that all jobs end with success and every starting job also ends and vice versa.
We start by filtering and displaying only the lines we are interested in:
Now let that run and watch if: a) the lines are filtered correctly and b) the names and conditions are displayed correctly. You can let the shell split the input lines and use different variables to distribute the split input to (all the ones i am not interested in i name "junk" out of habit), but it is easy to get the number of fields wrong in long lines. So try and verify it before going on. It is good practice make sure everything is correct so far before going on.
Next thing is to implement the "rules" we identified above. First the STARTING-lines:
We need to remember the date and time, so two of the fields not interested in before are now in a variable (junk->date, junk->time).
You see we just add to the arrays whe we find a new job, all very easy. The next rule is a a little trickier. Upon encountering such a line we need to search our array for the respective job entry, then print both starting and ending times:
Again, this is not meant to be put in production as it is. But analysing how we arrived at it and how it works should give you the idea how to create a proper script for your purpose.
I hope this helps.
bakunin
These 2 Users Gave Thanks to bakunin For This Post:
Sorry for the late response as I am out for some personal emergency. Thanks for your help, I am reviewing this now and will update you soon. Thanks again.
---------- Post updated at 07:31 AM ---------- Previous update was at 07:03 AM ----------
Of this file you only need the lines containing "STATUS: STARTING" and some ending notification. This could perhaps be "STATUS: SUCCESS", but somehow i don't believe that all jobs end that way - what other possible ending codes do you have, because your script will need to cover them too.
Let us go on, assuming for the moment that the only endng condition is "SUCCESS", this can be corrected later.
Next we make up some "rules" what to do with the respective lines, because at some point we need to read our input line by line:
- When we encounter a "STARTING" line we need to remember two things, the job name and the timestamp.
- When we encounter a "SUCCESS"-line we need to read also two things: the job name and the timestamp. But we don't need to store ("remember") them: the job name should be searched in our list of remembered (=started) jobs. If it is found, the stored starting time, the end time and the job name is printed.
The last point begs two questions: what are we going to do if we encounter a job with a start but no end? And what are we going to do with jobs with an end but no start?
Here is the skeleton of a shell script that implements what i said above. Neither is it very clever nor very mature, its intention to make it obvious how to implement common reasing like above into code. It also won't take the raised questions into account and implicitly assume that all jobs end with success and every starting job also ends and vice versa.
We start by filtering and displaying only the lines we are interested in:
Your above reply is very much correct and matches the exact requirement.
I tried the above script but it searches STARTING and SUCCESS for all job, whereas I need for specific job.
Also could you please tell what junk means ?
Can I use job name as $1 (1st arguement), so that it can changes as per requirement
Some comments:
- yes, you can introduce $1 as the job name to be discriminated in the input stream. Use if - then - else constructs for the evaluation.
- don't double-use variables (here: name) as it leads at least to confusion if not malfunction of the script.
- the inconsistent / faulty double quoting in the zgrep command might lead to the "No such file or directory" error. On top, I suspect DOS line terminators It causes "SUCCESS STATUS" to be the second parameter and thus interpreted as a file name.
- junk is a dummy variable to read and discard unneeded fields in the input line.
EDIT: It is not the DOS line terminator problem; corrected in above
Hi Techies,
I'm a newbie to PERL, Please help me with following problem.
I have an input text file like below
cat Input.txt
418673132,P
492538858,P
384535478,P
521522357,I
529435679,I
183617024,P
184414408,I
735510689,P
736238343,I
411642045,I
412690979,I
104232783,I (2 Replies)
Hello,
I'm having trouble with formatting some text via the terminal. I can get it perfectly formatted, but when I try and copy paste the text from the output file it loses it's formatting. Very frustrating!
Basically I have 7 files (data data2 data3 data4 data5 data6 data7) containing a... (13 Replies)
Can you please tell me how to just get only the output of dealers I & V information along with their subtotals in the next line of the file and create a new file, The dealer position along with corresponding totals may change everyday to any position above or below in the file, please help Thanks (2 Replies)
Dear All,
Good Day. I would like to hear your suggestions for the following problem:
I have a file with 5 columns with some numbers in 16 lines as shown below.
Input file:
Col 1 Col 2 Col 3 Col 4 Col 5
12 220 2 121 20
234 30 22 9... (3 Replies)
Hello,
I am working on one script which is giving output as a pipe "|" separated
abcd | efgh | 20090745
abcdefgh | efg | 20090622
Can any one please help me i want it to be formatted as pipe will be aligned, or the output looks like a table. (2 Replies)
Hi
I have the input file as below
***TEST10067
00567GROSZ 099
00567CTCTSDS90
***TEST20081
08233GROZWEWE
00782GWERW899
***TEST30088
08233GROZWEWE
00782GWERW899
I am finding the lines starting with *** and outputing as below
TEST10067
TEST20081
TEST30088
I need a space between TEST1... (9 Replies)
Hi
I have the following lines in a file
SWPRC000001NOT STATED 1344
SWPRC000001NOT STATED 1362
SWPRC000001NOT STATED 1418
SWPRC000001NOT STATED 1436
SWPRC000001NOT STATED ... (6 Replies)
Hi
I have the following records in a file
SABN YOURTUBE 000514 7256
SACN XYOUDSDF 000514 7356
SADN KEHLHRSER 000514 7656
SAEN YOURTUBE 000514 7156
SAFN YOURTUBE 000514 7056
I need to put this in the format like this
printf '%s %-50s %6s %-6s\n'
I am not going to read individual... (3 Replies)
var=12345
echo $var >>>12345
printf "%8.1f \n" $var >>> 12345.0
How to get this as 12,345?
I suppose I could break into sections by dividing by 1000 or 1000000.
But, is the a trick to this? (4 Replies)
Hi,
Is there some way to get formatted output in ksh? Something like a properly alligned tabular format. I tried adding '\t' to echo statements, but it doesn't come properly alligned
'hello' A simple Hello
'helloworld' A helloworld statement
I need the second coloumn to... (1 Reply)