Getting required fields from a text file in UNIX

My data is something like as shown below. Out of this i want the details of alarms (ex: 1947147711,1947147081......) and the fields( ex :sw=tacmwafabb9:shelf=1:slot=5-2:pport=2)
Once i have these details separated, i want the count of these excluding the duplicates. What is the best possible way to get this?

sample data:

(06/25/2009 00:03:35.674)( No default rules found for alarm:1947147711
(06/25/2009 00:03:35.676)(:ERROR) No rule found for alarm: sw=tacmwafabb9:shelf=1:slot=5-2port=2
(06/25/2009 00:03:42.198)( No default rules found for alarm:1947147081
(06/25/2009 00:03:42.200)(:ERROR) No rule found for alarm: sw=mdfdor33dsm:slot=9:pport=1:channel=1:lport=1
(06/25/2009 00:03:51.026)(:) No default rules found for alarm:1947147493
(06/25/2009 00:03:51.028)(:ERROR) No rule found for alarm: sw=lscrnmmabb7:shelf=1:slot=13-2:pport=6
(06/25/2009 00:03:53.961)(:) No default rules found for alarm:1947147711
 

Output required :

Alarm id Port
1947147711 sw=tacmwafabb9:shelf=1:slot=5-2:pport=2
1947147081 sw=mdfdor33dsm:slot=9:pport=1:channel=1:lport=1
1947147493 sw=lscrnmmabb7:shelf=1:slot=13-2:pport=6

Try this..

cat <input-file> | awk '{print $8}'

It's a little more complex than that, Jay,

awk '/alarm:[0-9]+$/ { split($NF,tmp,":");code=tmp[2]; } /No rule found for alarm: / { print code,$NF; }'

Once you have that output in, say "report.txt", you can get the "count" like this:

sort report.txt | uniq -c | sort -n 

It worked..Thanks a lot Jay :slight_smile:

Use this too..

cat <input-file> | awk '{print $8}' | paste - -

Otheus,

Your code is very helpful too...But i am not getting the details of alarms like 1947147711 and so on..
Please help.

---------- Post updated at 08:36 AM ---------- Previous update was at 08:34 AM ----------

i am getting details like this

alarm sw=mdfd33b0:shelf=.:slot=6:pport=4
alarm sw=scdlazmadsn:slot=7:pport=1:channel=3:lport=1
alarm sw=mplsmndtbbg:shelf=1:slot=9-1:pport=7
alarm sw=tcsnazmadsr:slot=8:pport=1:channel=25:lport=1
alarm sw=desmiadtbb4:shelf=1:slot=11-1:pport=1

Need alarm id's too.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Oops. Use tmp[2], not tmp[1]. I corrected the post.