いくつかの Python コードについて助けが必要です。これが可能かどうか教えてください。
コードを実行する前のメモ帳の 4050.log データ ファイルの例を次に示します。
port=4050
SOH=
hostname=BlueVectorEMA
uptime=N/A
SHTSOT=N/A
iCenter=N/A
start=51808152
stop=518083AA
cycles=0.0
tagCnt=23
C1Gen1=0.0.0.0
C1Gen2=0.0.0.0
STX=
00045512=119,59,55,60,50,C,00,N/A
00052450=120,60,44,60,43,C,00,N/A
00042260=113,54,51,59,43,C,00,N/A
00046999=114,56,46,58,42,C,00,N/A
00043166=117,58,46,59,42,C,00,N/A
00052651=113,55,48,58,42,C,00,N/A
00050594=118,59,43,59,43,C,00,N/A
00051774=120,60,44,60,42,C,00,N/A
00056767=119,59,43,60,42,C,00,N/A
00043181=109,51,56,58,45,C,00,N/A
00033333=115,56,55,59,43,C,00,N/A
00031475=115,57,43,58,45,C,00,N/A
00042817=118,59,48,59,50,C,00,N/A
00054245=118,58,45,60,41,C,00,N/A
00043589=118,58,46,60,43,C,00,N/A
00053037=116,57,54,59,48,C,00,N/A
00053636=114,55,45,59,42,C,00,N/A
00045642=116,57,49,59,42,C,00,N/A
00045591=118,59,46,59,45,C,00,N/A
00033114=116,58,46,58,44,C,00,N/A
00042075=114,56,54,58,48,C,00,N/A
00044491=113,55,42,58,43,C,00,N/A
00000587=18,0,999,18,46,T,403/002,0030H/3.0
ETX=
EOT=
timestamp=5180a211
logdir=2013-05
Wed May 1 00:03:13 2013
--------------------------------------------------------------------------------
port=4050
SOH=
hostname=BlueVectorEMA
uptime=N/A
SHTSOT=N/A
iCenter=N/A
start=518083AA
stop=51808602
cycles=0.0
tagCnt=23
C1Gen1=0.0.0.0
C1Gen2=0.0.0.0
STX=
00053636=119,59,44,60,41,C,00,N/A
00043181=107,48,56,59,45,C,00,N/A
00046999=116,57,46,59,42,C,00,N/A
00031475=117,58,43,59,45,C,00,N/A
00053037=115,55,54,60,48,C,00,N/A
00052651=117,58,47,59,42,C,00,N/A
00042075=117,57,54,60,48,C,00,N/A
00050594=118,59,43,59,43,C,00,N/A
00045512=115,55,55,60,50,C,00,N/A
00044491=113,55,42,58,43,C,00,N/A
00033114=115,57,46,58,44,C,00,N/A
00045591=117,58,46,59,46,C,00,N/A
00052450=117,58,44,59,43,C,00,N/A
00042260=114,56,51,58,42,C,00,N/A
00043166=116,58,47,58,42,C,00,N/A
00042817=117,59,48,58,50,C,00,N/A
00056767=119,59,43,60,42,C,00,N/A
00054245=119,59,45,60,41,C,00,N/A
00043589=117,57,46,60,43,C,00,N/A
00051774=118,59,44,59,42,C,00,N/A
00045642=113,55,50,58,42,C,00,N/A
00033333=111,53,55,58,44,C,00,N/A
00000587=7,0,999,7,47,T,402/202,0028H/2.5
ETX=
EOT=
timestamp=5180a469
logdir=2013-05
Wed May 1 00:13:13 2013
--------------------------------------------------------------------------------
次は、それが実行される python コードの例です --
#! /usr/bin/python
fob=open('C:/Users/dit3442/Desktop/4050.log','r')
listme=[n for n in fob.readlines() if not n.startswith('start') and \
not n.startswith('stop') and \
not n.startswith('timestamp=') and \
not n.startswith('hostname') and \
not n.startswith('00000') and \
not n.startswith('iCenter') and \
not n.startswith('tagCnt') and \
not n.startswith('ETX=') and \
not n.startswith('EOT=') and \
not n.startswith('logdir') and \
not n.startswith('port') and \
not n.startswith('uptime') and \
not n.startswith('SHTSOT') and \
not n.startswith('iCenter') and \
not n.startswith('start') and \
not n.startswith('stop') and \
not n.startswith('cycles') and \
not n.startswith('tagCnt') and \
not n.startswith('C1Gen2') and \
not n.startswith('STX=') and \
not n.startswith('--------') and \
not n.startswith('SOH=') and \
not n.startswith('\n') and \
not n.startswith('-------') and \
not n.startswith('C1Gen1')]
fob.close()
fob=open('C:/Users/dit3442/Desktop/4050C.log','w')
for line in listme:
fob.write(line.replace(',', '|').replace('=', '|').replace('Wed ', '').replace('Tue ',
'').replace('Thu ', '').replace('Fri ', '').
replace('May ', '05/').
replace(' 2013', '').replace('05/ ', '05/').replace(' ', '/2013 '))
fob.close()
次は、私が考えていることの例です-
00045512|119|59|55|60|50|C|00|N/A
00052450|120|60|44|60|43|C|00|N/A
00042260|113|54|51|59|43|C|00|N/A
00046999|114|56|46|58|42|C|00|N/A
00043166|117|58|46|59|42|C|00|N/A
00052651|113|55|48|58|42|C|00|N/A
00050594|118|59|43|59|43|C|00|N/A
00051774|120|60|44|60|42|C|00|N/A
00056767|119|59|43|60|42|C|00|N/A
00043181|109|51|56|58|45|C|00|N/A
00033333|115|56|55|59|43|C|00|N/A
00031475|115|57|43|58|45|C|00|N/A
00042817|118|59|48|59|50|C|00|N/A
00054245|118|58|45|60|41|C|00|N/A
00043589|118|58|46|60|43|C|00|N/A
00053037|116|57|54|59|48|C|00|N/A
00053636|114|55|45|59|42|C|00|N/A
00045642|116|57|49|59|42|C|00|N/A
00045591|118|59|46|59|45|C|00|N/A
00033114|116|58|46|58|44|C|00|N/A
00042075|114|56|54|58|48|C|00|N/A
00044491|113|55|42|58|43|C|00|N/A
05/1/2013 00:03:13
00053636|119|59|44|60|41|C|00|N/A
00043181|107|48|56|59|45|C|00|N/A
00046999|116|57|46|59|42|C|00|N/A
00031475|117|58|43|59|45|C|00|N/A
00053037|115|55|54|60|48|C|00|N/A
00052651|117|58|47|59|42|C|00|N/A
00042075|117|57|54|60|48|C|00|N/A
00050594|118|59|43|59|43|C|00|N/A
00045512|115|55|55|60|50|C|00|N/A
00044491|113|55|42|58|43|C|00|N/A
00033114|115|57|46|58|44|C|00|N/A
00045591|117|58|46|59|46|C|00|N/A
00052450|117|58|44|59|43|C|00|N/A
00042260|114|56|51|58|42|C|00|N/A
00043166|116|58|47|58|42|C|00|N/A
00042817|117|59|48|58|50|C|00|N/A
00056767|119|59|43|60|42|C|00|N/A
00054245|119|59|45|60|41|C|00|N/A
00043589|117|57|46|60|43|C|00|N/A
00051774|118|59|44|59|42|C|00|N/A
00045642|113|55|50|58|42|C|00|N/A
00033333|111|53|55|58|44|C|00|N/A
05/1/2013 00:13:13
私が必要とする唯一のことは、日付がそれらの上の対応する行と一致するようにすることです。
00052450|120|60|44|60|43|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00042260|113|54|51|59|43|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00046999|114|56|46|58|42|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00043166|117|58|46|59|42|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00052651|113|55|48|58|42|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00050594|118|59|43|59|43|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00051774|120|60|44|60|42|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
00056767|119|59|43|60|42|C|00|N/A|4050|BlueVectorEMA|05/01/2013 00:03:13
何かアイデアはありますか?