Quantcast
Viewing all articles
Browse latest Browse all 21975

Help with windows powershell - reading text file & manipulating the data

Hello,

I'm new to windows power shell & need your help/expertise in formatting the below *.txt file.

Could you please provide me with a sample powershell script which can accomplish the below request. Thank you so much for your help in advance.

<name>,<ticker>,<date>,<open>,<high>,<low>,<close>,<vol>,<oi>
GOOG 10-Jan-2014 1165 Put,GOOG140110P01165000,20140114,32.9,32.9,32.9,32.9,0,0
GOOG 10-Jan-2014 1170 Put,GOOG140110P01170000,20140114,40.87,40.87,40.87,40.87,0,0
GOOG 10-Jan-2014 1180 Put,GOOG140110P01180000,20140114,54.8,54.8,54.8,54.8,0,0
GOOG 10-Jan-2014 1190 Put,GOOG140110P01190000,20140114,50.9,50.9,50.9,50.9,0,0
GOOG 10-Jan-2014 1200 Put,GOOG140110P01200000,20140114,60.9,60.9,60.9,60.9,0,0
GOOG 10-Jan-2014 1300 Put,GOOG140110P01300000,20140114,157.8,157.8,157.8,157.8,0,0
PCLN 10-Jan-2014 1170 Call,PCLN140110C01170000,20140114,0.05,0.05,0.05,0.05,0,873
PCLN 10-Jan-2014 1172.5 Call,PCLN140110C01172500,20140114,0.01,0.01,0.01,0.01,0,136
PCLN 10-Jan-2014 1175 Call,PCLN140110C01175000,20140114,0.15,0.15,0.15,0.15,0,666
PCLN 10-Jan-2014 1177.5 Call,PCLN140110C01177500,20140114,0.05,0.05,0.05,0.05,0,174
PCLN 10-Jan-2014 1180 Call,PCLN140110C01180000,20140114,0.02,0.02,0.02,0.02,0,896
PCLN 10-Jan-2014 1182.5 Call,PCLN140110C01182500,20140114,0.07,0.07,0.07,0.07,0,138
PCLN 10-Jan-2014 1185 Call,PCLN140110C01185000,20140114,0.05,0.05,0.05,0.05,0,842
PCLN 10-Jan-2014 1187.5 Call,PCLN140110C01187500,20140114,0.05,0.05,0.05,0.05,0,36
PCLN 10-Jan-2014 1190 Call,PCLN140110C01190000,20140114,0.01,0.01,0.01,0.01,0,909
PCLN 10-Jan-2014 1192.5 Call,PCLN140110C01192500,20140114,0.2,0.2,0.2,0.2,0,88
PCLN 10-Jan-2014 1195 Call,PCLN140110C01195000,20140114,0.04,0.04,0.04,0.04,0,835
PCLN 10-Jan-2014 1197.5 Call,PCLN140110C01197500,20140114,0.25,0.25,0.25,0.25,0,22
PCLN 10-Jan-2014 1200 Call,PCLN140110C01200000,20140114,0.04,0.04,0.04,0.04,0,1073
PCLN 10-Jan-2014 1205 Call,PCLN140110C01205000,20140114,0.05,0.05,0.05,0.05,0,434
PCLN 10-Jan-2014 1210 Call,PCLN140110C01210000,20140114,0.03,0.03,0.03,0.03,0,346
PCLN 10-Jan-2014 1215 Call,PCLN140110C01215000,20140114,0.05,0.05,0.05,0.05,0,288

Z 22-Feb-2014 80 Call,Z140222C00080000,20140114,11.5,11.5,11.5,11.5,4,335
Z 22-Feb-2014 85 Call,Z140222C00085000,20140114,7.83,7.83,7.83,7.83,21,523
Z 22-Feb-2014 90 Call,Z140222C00090000,20140114,5.74,5.74,5.74,5.74,42,422
Z 22-Feb-2014 95 Call,Z140222C00095000,20140114,3.89,3.89,3.89,3.89,37,389
Z 22-Feb-2014 100 Call,Z140222C00100000,20140114,2.54,2.54,2.54,2.54,44,576
Z 22-Feb-2014 105 Call,Z140222C00105000,20140114,1.62,1.62,1.62,1.62,3,117
Z 22-Feb-2014 110 Call,Z140222C00110000,20140114,0.99,0.99,0.99,0.99,15,215

The ticker symbol in above file is max of 19 bytes. The software I use cannot convert this data, as it has a restriction of 14 bytes for ticker field.

I want to reduce the ticker field to 14 bytes using below logic & rewrite the modified symbol in the same column/file.

GOOG140110P01165000 - Ticker explanation is as shown below

Symbol : GOOG  ( 4 bytes)

Year : 14 ( 2 bytes)

Month : 01 ( 2 bytes)

Date : 10 ( 2 bytes)

Call/Put : C or P ( 1 byte) 

Strike : 01165 ( 5 bytes )

Strike (Decimal) : 000 ( 3 bytes)

Since they total to 19 bytes,my requirement is to bring down the ticker field size to 14 bytes using below formula.

1) Reduce year field to 1 byte i.e. 14 can be kept as 4

2) Strike ( Decimal) can be reduced to 1 byte ( drop the ending 2 bytes)

3) Month column ( 2 bytes) & call/put ( 1 byte) can be reduced to 1 byte ( saving of 2 bytes) by replacing 01 & C combination with A , 01 & P combination with B so on as mentioned below.

Month( 2 bytes)Call/Put ( 1 byte)Replace with
01CA
01PB
02CC
02PD
03CE
03PF
04CG
04PH
05CI
05PJ
06CK
06PL
07CM
07PN
08CO
08PP
09CQ
09PR
10CS
10PT
11CU
11PV
12CW
12PX

So the modified ticker will look like GOOG4B10011650

GOOG - symbol

4 - year which is 2014 in this case 

B- 01 ( jan) & Put (P) is replaced with letter B

10 - Date

01165 - Strike price

0 - Decimal portion of strike price

The output file should look like below.

<name>,<ticker>,<date>,<open>,<high>,<low>,<close>,<vol>,<oi>
GOOG 10-Jan-2014 1165 Put,GOOG410B011650,20140114,32.9,32.9,32.9,32.9,0,0

Thank you for your inputs with this request.

Regards,

Aimforsky


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>