Home > bash > awk – post text within ranges

awk – post text within ranges

Problem: Get the name of the applications reporting an error.

Sample file.

shell> cat file
——————————————————————————-
—— Primary No : @(#) 7.03.05
——————————————————————————-
Application : VPSP0006
Date: 04/04/2011
Type of treament : 2
Number of examples : 1
——————————————————————————-
—— Messages : (var/log) vpsp00066901.log ——
——————————————————————————-
—- == END =========
——————————————————————————-
—— Primary No : @(#) 7.03.05
——————————————————————————-
Application : VPSP0007
Date: 04/04/2011
Type of treatment : 0
Number of examples : 5
——————————————————————————-
—— Messages : (var/log) vpsp00076901.log ——
——————————————————————————-
—- == ERROR ===
——————————————————————————-
—— Primary No : @(#) 7.03.05
——————————————————————————-
Application : VPSP0008
Date: 04/04/2011
Type of treatment : 29
Number of examples : 19
——————————————————————————-
—— Messages : (var/log) vpsp00086901.log ——
——————————————————————————-
—- == END =========

Solution:

awk '/Application : /{app=$3}/== ERROR === / {print app}'  file

How it works:
Awk searches for the string Application, saves the third field in a variable, then searches for the string ERROR and if it finds it prints the saved variable.

source: www.unix.com

Advertisements
Categories: bash Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: