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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting check for the value of one particular field and give output in a different file
# 1  
Old 06-22-2008
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(ArcSDEConnection Pool.java:251)
com.telenity.canvas.lbs.poolconf.arcsde.ArcSDEConnectionPool.run(ArcSDEConnectionPool.java:274)
java.lang.Thread.run(Thread.java:534)


Aemunathan
# 2  
Old 06-22-2008
With awk:

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

Regards
# 3  
Old 06-23-2008
$3 not $2

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

to put value in a different file, just redirect:

awk '/\[Alarm Severity\]:/ {print $3}' file > newfile
# 4  
Old 06-24-2008
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
# 5  
Old 06-24-2008
use a case statement

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

case $severity in
MINOR) <statements> ;;

MAJOR) <statements> ;;

...
...

esac

not sure if this is the best way...
# 6  
Old 06-24-2008
Quote:
Originally Posted by ynir
awk '/\[Alarm Severity\]:/ {print $3}' file

to put value in a different file, just redirect:

awk '/\[Alarm Severity\]:/ {print $3}' file > newfile
The default fieldseperator is a space so to get the value MINOR you have to print the 2nd field.

Regards
# 7  
Old 06-24-2008
Quote:
Originally Posted by Franklin52
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. Smilie
Code:
# echo "[Alarm Severity]: MINOR" | awk '/\[Alarm Severity\]:/{print $2}'
Severity]:
# echo "[Alarm Severity]: MINOR" | awk '/\[Alarm Severity\]:/{print $3}'
MINOR

Am I missing something?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to check field value from a file records

I need a script to check the records in a file , if any value match transfer the record in error.txt file. 1- If any of the any field value is NULL(nothing in this field) Record1|Record2|Record3|Record4|Record5|DATE1|DATE2 Example: 11111111|22222222|NULL|12|444|27042018|27042018... (8 Replies)
Discussion started by: vivekn
8 Replies

2. UNIX for Dummies Questions & Answers

ID incorrect field values in dat file and output to new file

Hi All I have a .dat file, the values are seperated by ". I wish to identify all field values in field 14 that are not '01-APR-2013' band then copy those records to a new file. Can anyone suggest the UNIX command required. Thanks in advance Andy (2 Replies)
Discussion started by: aurum1313
2 Replies

3. Shell Programming and Scripting

Need to check the value greater than or less than and give out put to a file

HI, I have one file which is as below cat /var/tmp/test1 | awk '{ print $3}'|grep -v affected Data ---------- 200.4 . The above 200 value is changable by the database script. Now I need a script that checks the value 200.4 and the script shoud give out put if value is more than 225 (2 Replies)
Discussion started by: phani4u
2 Replies

4. Shell Programming and Scripting

Plz Help. Compare 2 files field by field and get the output in another file.

Hi Freinds, I have 2 files . one is source.txt and second one is target.txt. I want to keep source.txt as baseline and compare target.txt. please find the data in 2 files and Expected output. Source.txt 1|HYD|NAG|TRA|34.5|1234 2|CHE|ESW|DES|36.5|134 3|BAN|MEH|TRA|33.5|234... (5 Replies)
Discussion started by: i150371485
5 Replies

5. Shell Programming and Scripting

Compare two files Field by field and output the result in another file

Hi Friends, Need Help. I have file1.txt as File1.txt |123|A|7267|Hyder|Cross|Sell|7801 |995|A|7051|2008|Lunar|New|Year|Promotion|7801 |996|A|7022|Q108|Targ|Prospect|&|SSCC|Savings|Promo|7801 |997|A|7182|Q1|Feb-Apr|08|Credit|ITA|PA|SBA|Campaign|7801 File2.txt... (7 Replies)
Discussion started by: i150371485
7 Replies

6. Shell Programming and Scripting

Take name of input file to give the name of output file

Hello everyone, I think this would be easy for you experts. Refering the suggestion that Scrutinizer gave me in this thread https://www.unix.com/302612499-post13.html I have the script in this form awk '{$1=$1}1' "$1" | awk ' ...' Where "$1" takes the value of "inputfile" then I can... (1 Reply)
Discussion started by: Ophiuchus
1 Replies

7. Shell Programming and Scripting

How to check field formatting of input file?

Hi, I had input file with below data, abcdefghij;20100903040607;1234567891;GLOBAL; Having values of fields with seperated by semi-colon (;) and ended with line feed (\n). Through shell script, how can I check the field formatting? Thanks in advance. (18 Replies)
Discussion started by: Poonamol
18 Replies

8. Shell Programming and Scripting

simplify the script, check field match to value in a file

Hi Everyone, Below is the script, i feel there should be more simple way to do the same output, my one works, but feel not nice. like using index i feel it is slow (image my file is very large), maybe awk can do one line code? Please advice. # cat 1.txt 1 a 2 b 3 cc 4 d # cat 1.pl... (6 Replies)
Discussion started by: jimmy_y
6 Replies

9. Shell Programming and Scripting

avoid open file to check field.

Hi Everyone, # cat a.txt 94,aqqc,62345907, 5,aeec,77, # cat 1.pl #!/usr/bin/perl use strict; use warnings; use Date::Manip; open(my $FA, "/root/a.txt") or die "$!"; while(<$FA>) { chomp; my @tmp=split(/\,/, $_); if (index($tmp, "qq") ne -1) { ... (4 Replies)
Discussion started by: jimmy_y
4 Replies

10. UNIX for Dummies Questions & Answers

Output Multiple Field from dataBase file

I am fairly new in unix I was wondering if anybody can help me out with this: I am trying to output to a file the following fields; Field1 Field2 Field4 From a database file dataBase1. this is how the file looks: dataBase1 TABLE DATA Example ================== Table ... (3 Replies)
Discussion started by: Dennz
3 Replies
Login or Register to Ask a Question