![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
|||
|
Quote:
Code:
#!/bin/sh #set -x file=$1 echo $file while read line; do echo $line done < $file |
|
|||
|
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
|
|
|||
|
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
|
|||
| Google The UNIX and Linux Forums |