Sponsored Content
Top Forums Shell Programming and Scripting Shell Script for formatted output Post 303001790 by Sandeep Behera on Friday 11th of August 2017 07:31:50 AM
Old 08-11-2017
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



Code:
#! /bin/ksh

name=$1

typeset    infile="/home/sbehera/out/event_demon.ACE*"      # file we read from
typeset    cond="SUCCESS"                               # condition of the job, "STARTING" or "SUCCESS"
typeset -i count=1                               # counter for the newest element of the storage arrays
typeset -i i=1                                     # counter for searching the storage arrays

echo $infile $cond $name $count $i


zgrep ""STATUS: SUCCESS"  "STATUS: STARTING"" "$infile" |\
while read date time junk junk junk junk cond junk name junk ; do

     echo "name is: $name   condition is: $cond  time is: $date $time"       # we leave that in for now, to see what the script works on


case $cond in
          STARTING)
               typeset aname[$count]="$name"
               typeset atime[$count]="$date $time"
               (( count += 1 ))
               ;;

          SUCCESS)
               (( i = 1 ))
               while [ $i -lt ${#aname[@]} ] ; do               # walk though the array
                    if [ "${aname[$i]}" = "$name" ] ; then     # we found the corresponding entry
                         print "${aname[$i]} \t${atime[$i]} \t $date $time"
                    else
                         (( i += 1 ))
                    fi
               done
               ;;

     esac
done

exit 0




Output:

$ sh run.sh IOXXXXXMO_XXXILEO
/home/sbehera/out/event_demon.ACE 
/home/sbehera/out/event_demon.ACE.07092017.gz 
/home/sbehera/out/event_demon.ACE.07102017.gz 
/home/sbehera/out/event_demon.ACE.07112017.gz 
/home/sbehera/out/event_demon.ACE.07122017.gz 
/home/sbehera/out/event_demon.ACE.07132017.gz 
/home/sbehera/out/event_demon.ACE.07142017.gz 
/home/sbehera/out/event_demon.ACE.08102017.gz SUCCESS IOXXXXXMO_XXXILEO 1 1
SUCCESS  STATUS:.gz: No such file or directory
STARTING.gz: No such file or directory
/home/sbehera//out/event_demon.ACE*.gz: No such file or directory


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 08-11-2017 at 08:54 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatted output in KSH

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)
Discussion started by: psynaps3
1 Replies

2. Shell Programming and Scripting

formatted output with commas

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)
Discussion started by: joeyg
4 Replies

3. Shell Programming and Scripting

Formatted output - awk

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)
Discussion started by: dhanamurthy
3 Replies

4. Shell Programming and Scripting

Formatted Output

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)
Discussion started by: dhanamurthy
6 Replies

5. Shell Programming and Scripting

cut - columns with formatted Output

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)
Discussion started by: dhanamurthy
9 Replies

6. Shell Programming and Scripting

Formatted output of shell script

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)
Discussion started by: vikash_k
2 Replies

7. Shell Programming and Scripting

output - tab formatted - awk

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)
Discussion started by: Fredrick
3 Replies

8. UNIX for Dummies Questions & Answers

Request for Formatted Output

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)
Discussion started by: Ariean
2 Replies

9. Shell Programming and Scripting

Shell Script Problems, Lose formatting when copy pasting from formatted file.

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)
Discussion started by: facetoe
13 Replies

10. Programming

Formatted output in PERL

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)
Discussion started by: mahi_mayu069
2 Replies
All times are GMT -4. The time now is 10:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy