# Need a Python script

**URL:** <https://community.unix.com/t/need-a-python-script/320439>\
**Category:** Shell Programming and Scripting\
**Created:** [November 27, 2012, 10:53am UTC](https://community.unix.com/t/need-a-python-script/320439 "2012-11-27T10:53:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vijeta\_Laad](https://community.unix.com/letter_avatar/vijeta_laad/32/6_22734026db12803ebb3e059622ac3534.png) [@Vijeta\_Laad](https://community.unix.com/u/Vijeta_Laad)\
**Post date:** [November 27, 2012, 10:53am UTC](https://community.unix.com/t/need-a-python-script/320439/1 "2012-11-27T10:53:29Z")

</div>

I work on various messages received from server and want to write a python script that can sort messages with unique flag values and give me the output in a text file.  
I get these messages in the form of .zcap file from server, in order to get messages from those files; I use an internal tool:

1. 

```
  To filter the zcap file and get security types,

```

2. 

```
  To filter each security type to get various exchanges and

```

3. 

```
  To filter each exchange for message types.

```

[CENTER]BOND  
([/CENTER]

For eg: I filtered a .zcap file to get message types as -

[CENTER]CVE

NYSE

TSE[/CENTER]

Each exchange have different message types like:  
CVE- MTR\_BOND, MTFD\_BOND, MTQ\_BQUOTE  
NYSE- MTR\_BOND,MTQ\_MBBOQUOTE, MTA\_RECAP,  
TSE- MTR\_BOND, MTFD\_BOND, MTT\_TRADE, MTT\_STATUS, MTA\_CLOSE

I have a unix command to run at message type level that generates 1 file of each unique flag value messages.  
$ awk '/MTR/,/Close Time/{a[i\+\+]=$0;if($0~/Flags:/){sub(":","",$2);fname=$2}if($0~/Close Time/){for(j=0;j\<=i;j++)print a[j] \>\> fname;i=0}}' input.txt

But this is a tedious job to run this command for each message type (for eg; MTR\_BOND) and create files for unique flag value messages. I want a script that I can run at Security type level (for eg; Bond)  
Here I attach text file for BOND and its exchanges and message types. Please write a python script (preferably) to generate 1 text file for each message types with only 1 message of unique flag value.
