check for the value of one particular field and give output in a different file

hi
i need to check for the value of one particular field [Alarm Severity]: in the output file. the file may contain many such records as below

how to ????

*** Throttled with base name + key params!
[Alarm]:
[Inst Id]: -518594328
[Instance Name]: les.alarm.LBS12005
[Base Name]: les.alarm.LBS12005
[Cluster Name]: les
[Hostname]: lessrv1
[Module Name]: les
[Process Id]: 2328
[User Id]: 0
[Group Id]: 1
[Permission]: rwrwr-
[Alarm Severity]: MINOR
[Alarm Type]: EVENT
[Is Nested]: false
[Pin Type]: AUTOMATIC
[Alarm Text]: ArcSDE Server Not Responding. poolName: = arcsde10
[Start Time]: 2008-05-04 11:22:33:658
[Stop Time]: 2008-05-04 11:22:33:658
[Count]: 1
[Stack Trace]:
com.telenity.canvas.alarm.CanvasAlarm.raiseBcompAlarm(CanvasAlarm.java:637)
com.telenity.canvas.alarm.CanvasAlarm.doOLDAlarmWithHost(CanvasAlarm.java:550)
com.telenity.canvas.alarm.CanvasAlarm.doOLDEventAlarm(CanvasAlarm.java:917)
com.telenity.canvas.alarm.CanvasAlarm.EventAlarm(CanvasAlarm.java:912)
com.telenity.canvas.lbs.poolconf.arcsde.ArcSDEConnectionPool.makeNewConnection(ArcSDEConnectionPool.java:127)
com.telenity.canvas.lbs.poolconf.arcsde.ArcSDEConnectionPool.refreshFreeConnections(ArcSDEConnectionPool.java:251)
com.telenity.canvas.lbs.poolconf.arcsde.ArcSDEConnectionPool.run(ArcSDEConnectionPool.java:274)
java.lang.Thread.run(Thread.java:534)

Aemunathan

With awk:

awk '/\[Alarm Severity]:/{print $2}'  file

Regards

awk '/\[Alarm Severity\]:confused: {print $3}' file

to put value in a different file, just redirect:

awk '/\[Alarm Severity\]:confused: {print $3}' file > newfile

hi

thanks for the help. but i have not given u my exact requirement there.

actually i need to check the status of alarm severity: MINOR OR MAJOR OR .... then if its major, fetch the alarm text field in the same file as well as start time to another file which i can fetch later on to send sms to the predefined numbers

use a case statement

severity=`awk '/\[Alarm Severity\]:confused: {print $3}' file`

case $severity in
MINOR) <statements> ;;

    MAJOR\)  &lt;statements&gt; ;;

...
...

esac

not sure if this is the best way...

The default fieldseperator is a space so to get the value MINOR you have to print the 2nd field.

Regards

You're right, but as you see the requested field has space within it, so you need $3. :slight_smile:

# echo "[Alarm Severity]: MINOR" | awk '/\[Alarm Severity\]:/{print $2}'
Severity]:
# echo "[Alarm Severity]: MINOR" | awk '/\[Alarm Severity\]:/{print $3}'
MINOR

Am I missing something?

Oh my, you're right!