The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
extract x lines after a pattern - place each result in separate file gobi Shell Programming and Scripting 5 06-06-2008 12:03 PM
display the result of wc -l with words before and after the result melanie_pfefer UNIX for Dummies Questions & Answers 3 04-30-2008 04:33 AM
egrep counting every 2 lines of result as 1 Orbix UNIX for Dummies Questions & Answers 1 11-20-2007 04:12 PM
Help in outputting the result in log files dave_nithis Shell Programming and Scripting 23 09-28-2007 04:44 AM
MQ and AIX, result transfer to a file ?? varungupta UNIX for Advanced & Expert Users 1 09-10-2007 04:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2007
Registered User
 

Join Date: Nov 2007
Posts: 3
Thumbs up Outputting formatted Result log file from old 30000 lines result log<help required>

Well I have a 3000 lines result log file that contains all the machine data when it does the testing... It has 3 different section that i am intrsted in

1) starting with "20071126 11:11:11 Machine Header 1"
1000 lines...

"End machine header 1"

2) starting with "20071126 12:12:12 Machine Header 2"
1000 lines...

"End machine header 2"

2) starting with "20071126 12:12:12 Machine Header 3"
1000 lines...

"End machine header 3"


With this their are a lot of junk data also..
I just want to grab these 3 headers and put in into different file With each header having his own sections
eg:
===================Header1 Start====================
<it's content>
===================Header1 End ====================
how I can do this .. I want something like this

./<New script> <old log file>

and it gives me a new log file.

Can you please help me in making this... I want to make it in bash scripting.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 11-29-2007
Registered User
 

Join Date: Nov 2007
Posts: 3
Hey guys.. Please show me some pointers.. Its kinda very urgent.
Reply With Quote
  #3 (permalink)  
Old 11-29-2007
Moderator
 

Join Date: Feb 2007
Posts: 1,965
Rule 4 of the SIMPLE RULES OF THE UNIX FORUMS:

Do not 'bump up' questions

And now the obligatory question: is this a homework question? If so, we can't help you.
That's against rule 6:

Do not post classroom or homework problems.

Assuming that it's not, can you show us how far you've gotten so far?

Regards
Reply With Quote
  #4 (permalink)  
Old 11-29-2007
Registered User
 

Join Date: Nov 2007
Posts: 3
Quote:
Originally Posted by Franklin52 View Post
Rule 4 of the SIMPLE RULES OF THE UNIX FORUMS:

Do not 'bump up' questions

And now the obligatory question: is this a homework question? If so, we can't help you.
That's against rule 6:

Do not post classroom or homework problems.

Assuming that it's not, can you show us how far you've gotten so far?

Regards
Well Its not an Class Room as well as homework problem.. I am trying to make some real world test result documentation script.As i am new to shell domain.. I am not able to figure out this that easily, Till now I have done this much
Code:
#!/bin/sh
#set -x
file=$1
echo $file
while read line;
do 
echo $line 
done < $file
With this I am able to read my file properly but the data is not coming with proper indentation, It is loosing its initial spacing which I dont want.
Reply With Quote
  #5 (permalink)  
Old 11-30-2007
Moderator
 

Join Date: Feb 2007
Posts: 1,965
If awk is allowed (anyhow it gives a direction to figure it out in bash):

Code:
#!/bin/sh

awk '
{
  if($0 ~ /^starting with .*Header /) {
    i++
    print "===Header"i " Start==="
    flag=1
    next
  }
  if($0 ~ /^"End Machine Header /) {
    print "===Header"i " End==="
    if(i==3) {
      exit
    }
    flag=0
  }
  if(flag) {
    print $0
  }
  next
}' $1
Regards
Reply With Quote
  #6 (permalink)  
Old 12-02-2007
Registered User
 

Join Date: Jun 2007
Posts: 377
awk

Hi,

This one:

Code:
awk '(NF==5 && $3=="Machine" && $4=="Header"){
flag=1
file=sprintf("%s.txt",$5)
}
(flag==1) {
print $0 >> file
close(file)
}
(NF==4 && $2=="machine" && $1=="End"){
flag=0
}' filename
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0