Shell Script for formatted output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script for formatted output
# 1  
Old 07-27-2017
Shell Script for formatted output

Code:
06/26/2017 23:40:40       CAUAJM_I_10082 [aspsun14 connected for IOALPPRXXBD_ALPGLGENFAALL 55443.15215291.1]
 06/26/2017 23:40:40       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: STARTING        JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14
 06/26/2017 23:40:42       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: RUNNING         JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14
 06/26/2017 23:49:19       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: SUCCESS         JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14        EXITCODE:  0
 06/27/2017 23:40:23       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: STARTING        JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14
 06/27/2017 23:40:24       CAUAJM_I_10082 [aspsun14 connected for IOALPPRXXBD_ALPGLGENFAALL 55443.15236942.1]
 06/27/2017 23:40:25       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: RUNNING         JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14
 06/27/2017 23:48:19       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: SUCCESS         JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14        EXITCODE:  0
 06/28/2017 23:41:36       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: STARTING        JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14
 06/28/2017 23:41:37       CAUAJM_I_10082 [aspsun14 connected for IOALPPRXXBD_ALPGLGENFAALL 55443.15258301.1]
 06/28/2017 23:41:38       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: RUNNING         JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14
 06/28/2017 23:48:47       CAUAJM_I_40245 EVENT: CHANGE_STATUS    STATUS: SUCCESS         JOB: IOALPPRXXBD_ALPGLGENFAALL MACHINE: aspsun14        EXITCODE:  0

I have a file having above content, I want the output like, job name then start time then End time
Code:
IOALPPRXXBD_ALPGLGENFAALL 06/26/2017 23:40:40 06/26/2017 23:49:19
IOALPPRXXBD_ALPGLGENFAALL 06/27/2017 23:40:23 06/27/2017 23:48:19
IOALPPRXXBD_ALPGLGENFAALL 06/28/2017 23:41:36 06/28/2017 23:48:47

could somebody help me with a shell script for this requirement. I am using ksh in AIX environment

Moderator's Comments:
Mod Comment Please use code tags for data examples

Last edited by jim mcnamara; 07-27-2017 at 09:13 AM..
# 2  
Old 07-27-2017
Good, well formed question for a first effort.

What have you tried so far?
Can you show us where you are stuck? The point of the forums is to help you learn, not to write code for you.
These 2 Users Gave Thanks to jim mcnamara For This Post:
# 3  
Old 07-28-2017
Quote:
Originally Posted by jim mcnamara
Good, well formed question for a first effort.

What have you tried so far?
Can you show us where you are stuck? The point of the forums is to help you learn, not to write code for you.

Code:
#!bin/ksh

job_name=$1
echo $job_name

ls /Autosys/CA/UnicenterAutoSysJM/autouser.ACE/out/event_demon.ACE* | sort -r | awk -F "/" '{print $7}' > logfile.txt

path="/Autosys/CA/UnicenterAutoSysJM/autouser.ACE/out"


 while read line;

 do

                            zgrep $job_name $path/$line  | sed -e 's/\[/ /' -e 's/\]/ /'  >> feoj.txt



  done < logfile.txt

cat feoj.txt | sort -k1 | awk '/START|SUCCESS/ { print $1,$2}'

Thanks for the reply. I have tried this but the out put is in one column, please give me some hint so that I can try.


Moderator's Comments:
Mod Comment
Please wrap all code, files, input & output/errors in CODE tags.
It makes it easier to read and preserves multiple spaces for indenting or fixed-witch data.

Last edited by rbatte1; 07-28-2017 at 08:26 AM.. Reason: Code tags
# 4  
Old 07-28-2017
A few pointers to tidy up first:-
  • Please wrap CODE tags [CODE] & [/CODE] around code, files, input & output/errors.
  • The append to feoj.txt can be added to the end of the loop
  • There is no need to use cat to pipe the file, just name the file as part of the command
  • Putting the awk before the sort will mean sort has less processing to do.
  • If you don't need to store the file, you can avoid the IO altogether.
  • What are the full filenames for the log files? The logfiles should be in order if they have a correct timestamp in the name.
    If they are just aged my moving them through the suffixes of -1, -2, -3 etc., then we can adjust for that.

Doing just these (but not removing the final sort) gives me this:-
Code:
#!bin/ksh

job_name=$1
echo $job_name

path="/Autosys/CA/UnicenterAutoSysJM/autouser.ACE/out"

cd $path                        # ..... or 'pushd $path' if you prefer so you can 'popd' later if needed

for filename in event_demon.ACE*
do
   zgrep $job_name $filename  | sed -e 's/\[/ /' -e 's/\]/ /'
done  | awk '/START|SUCCESS/ { print $1,$2}' | sort -k1


Now that it's a bit neater, where is it going wrong?


Kind regards,
Robin

Last edited by rbatte1; 07-28-2017 at 09:22 AM..
This User Gave Thanks to rbatte1 For This Post:
# 5  
Old 07-28-2017
I am quite enthused you left something over for me, dear colleague ;-)

Quote:
Originally Posted by rbatte1
Code:
#!bin/ksh

should of course be:

Code:
#! /bin/ksh

I hope this helps.

bakunin
These 2 Users Gave Thanks to bakunin For This Post:
# 6  
Old 07-28-2017
yes it works, but my concern with the output format.

How can I display the value of variable side by side like below :


Code:
Job Name                                  Start Time                 End Time
IOALPPRXXBD_ALPGLGENFAALL 06/26/2017 23:40:40 06/26/2017 23:49:19
IOALPPRXXBD_ALPGLGENFAALL 06/27/2017 23:40:23 06/27/2017 23:48:19
IOALPPRXXBD_ALPGLGENFAALL 06/28/2017 23:41:36 06/28/2017 23:48:47


Last edited by rbatte1; 07-28-2017 at 09:17 AM.. Reason: Code tags again. Warning issued.
# 7  
Old 07-28-2017
Can you show us (wrapped in CODE tags please) what you get so far. We can then think about how to progress. Otherwise we're a bit blind.

What do you want to happen if there is not a closing SUCCESS record in the log file?



Regards,
Robin

Last edited by rbatte1; 07-28-2017 at 09:25 AM.. Reason: Question about failed or incomplete messages
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question