Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print all lines after trigger word

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
I'm looking to output all lines from a log file after a certain trigger word. What I have so far is
Code:
last_occurence=$(grep -n $trigger $file|tail -1|cut -d : -f 1)
line_count=$(wc -l $file)
required_lines=$(expr $line_count - $last_occurence)
tail -$required_lines $file
but there must be a better way using sed or awk.

Any hints please?

Ceci n'est pas une signature
Columb Healy
 
awk -v trigger="${trigger}" '{
if (found) print
if ($0~trigger) found=1
}' /path/to/logfile

HTH,

p5wizard
 
Sorry, my mistake, I forgot to say that it's all lines after the last occurence of the trigger word.

Ceci n'est pas une signature
Columb Healy
 
with an array:

awk -v trigger="${trigger} '{
if (found) a[found++]=$0
if ($0~trigger) found=1
}
END{
for (i=1;i<found;i++) print a
}'

HTH,

p5wizard
 
Perfect!

Many thanks

Ceci n'est pas une signature
Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top