shell program code logic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting shell program code logic
# 1  
Old 02-04-2009
shell program code logic

Hi,

I have a file (log data) with the sample code as follows

/apps/opt | go_gen.ksh | #START | jan 28 06:15 |/home/dump
/apps/opt | go_gen.ksh | #END | jan 28 06:30 |/home/dump

/apps/opt | pend_instl.ksh | #START | jan 28 09:50 |/home/dump

/apps/opt | pend_instl.ksh | #END | jan 28 09:55 |/home/dump

/apps/opt | go_gen.ksh | #START | jan 28 11:30 |/home/dump

/apps/opt | go_gen.ksh | #END | jan 28 11:35 |/home/dump

/apps/opt | create_dump.ksh| #START | jan 28 12:51 |/home/dump

/apps/opt | create_dump.ksh| #END | jan 28 12:52|/home/dump

/apps/opt | go_gen.ksh | #START | jan 28 11:30 |/home/dump

/apps/opt | go_gen.ksh | #START | jan 28 15:30 |/home/dump
/apps/opt | go_gen.ksh | #END | jan 28 15:35 |/home/dump
/apps/opt | installed.ksh| #START | jan 28 15:56 |/home/dump

/apps/opt | installed.ksh| #END | jan 28 15:59 |/home/dump
.
.
.
(100s of logs of same format)
I need to write a shell program to create a file which contains
(1st field (file path),2nd field (file name),4th field(start time),end time (in line having #END) and 5th field(log path)..for each filename

for ex: take line1 and line2 in the sample data i mentioned..they corresponds to on file name,first line giving star time and second line giving end time.

The Problem is
1)for certain files like go_gen.ksh (highlighted as bold),there are more tha one entry in the inputlog file.I need to generate corresponding start and end times(which i am unable to get while writing in a while loop) in the new file.
2) for certain filenames like "/apps/opt | go_gen.ksh | #START | jan 28 11:30 |/home/dump" there is no corresponding ENDTIME.In such case i need to put a '-' in the endtime field in newfile.


Need to write a shell program.Please can u give me the outline and rough code.Since i am new to shell programming,i am unaware of most of the functions/commands.(even awk/sed is permisable)

Reply me as soon as possible.


Thanks in anticipation.
# 2  
Old 02-04-2009
Could you post an example the expected output?
# 3  
Old 02-04-2009
output should look like this

The output should like this..(for the data mention above)

/apps/opt |go_gen.ksh |jan 28 06:15 |jan 28 06:15 |/home/dump
/apps/opt |pend_instl.ksh |jan 28 09:50 |jan 28 09:55 |/home/dump
/apps/opt |go_gen.ksh | jan 28 11:30 |jan 28 11:35 |/home/dump
/apps/opt | create_dump.ksh|jan 28 12:51 |jan 28 12:52|/home/dump
/apps/opt | go_gen.ksh |jan 28 11:30 |- |/home/dump
apps/opt | installed.ksh| jan 28 15:56|jan 28 15:59 |/home/dump
# 4  
Old 02-04-2009
Given your example input you may try something like this:

[use gawk, nawk or /usr/xpg4/bin/awk on Solaris]
Code:
awk -F\| 'END { 
  print s, t[1], t[2] ? t[2] : " - ", l 
  }
/#START/ && s { 
  print s, t[1], t[2] ? t[2] : " - ", l 
  split(FS, t); c = 0
  }  
NF { s = $1 FS $2; l = $5; t[++c] = $4 }
' OFS=\| infile

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read files in shell script code and run a C program on those files

HI, I am trying to implement a simple shell script program that does not make use of ls or find commands as they are quite expensive on very large sets of files. So, I am trying to generate the file list myself. What I am trying to do is this: 1. Generate a file name using shell script, for... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

2. Shell Programming and Scripting

Shell script logic

Hi I have a requirement where I have to generate a mail/alert to the user if any QA check is failed. our oracle jobs run in unix environment and log file is created . Sample is given below . SELECT * FROM product.fact_tally WHERE period_id = '20130401' ; LIMIT 5; Ideally the above... (4 Replies)
Discussion started by: systemee
4 Replies

3. Shell Programming and Scripting

Need logic for shell scripting

I am comfortable with shell scripting. I need a better logic for below, I've a reference file, to take the parameter value. For example in the no of channel is 6 i have get the commands as written below. I need need a differenct logic to extract the commands. NO_OF_CHANNEL=6 case... (3 Replies)
Discussion started by: ilugopal
3 Replies

4. Programming

need logic for java program

Hi All, I need to to wright a java programm for the following query. Qus: output need to genarate a number+ alphnumric sequence in java and get converted into ASCII code so that i can use mod logic on that. example Output: like 10 digit number 1AAAAAAAAA 1AAAAAAAAB 1AAAAAAAAC . .... (4 Replies)
Discussion started by: Ganesh Khandare
4 Replies

5. Shell Programming and Scripting

Shell or PERL Logic

Hello All, Currently i am working on a logic in PERL scripting ... But i am sort of stuck up, can any one please help. Here goes. 1. Search for a pattern in a file 2. If the pattern matched lets say 10 lines 2.1 Reterive the first line and check for another pattern 2.1.1 if... (1 Reply)
Discussion started by: maxmave
1 Replies
Login or Register to Ask a Question