文本内容如下:
12-06 14:50:23.600: I/ActivityManager(605): Displayed com.suning.numberlocation/.NumberLocationActivity: +125ms
12-06 14:50:52.581: I/ActivityManager(605): Displayed com.suning.numberlocation/.NumberLocationActivity: +126ms
12-06 14:51:21.391: I/ActivityManager(605): Displayed com.suning.numberlocation/.NumberLocationActivity: +108ms
12-06 14:51:50.652: I/ActivityManager(605): Displayed com.suning.numberlocation/.NumberLocationActivity: +121ms
想使用python截取每一行中的特定数据,然后把它们写入到csv文件中!
想截取每一行中的3段字符串 “numberlocation” “NumberLocationActivity” “125”
在CSV中看到的期待结果是(一行输出3段字符串):
numberlocation NumberLocationActivity 125
å设 ä½ çæ件åå«t.txtå¨å½åç®å½ä¸,
è¾åºçCSVå«csv.txtä¹å¨å½åç®å½
代ç å¦ä¸
import sysè¿æ ·çæä¹å¤çï¼12-09 15:05:45.748: I/ActivityManager(557): Displayed com.android.phone/.PrivilegedOutgoingCallBroadcaster: +388ms
å
容ä¼ååè¿éé¢phoneï¼PrivilegedOutgoingCallBroadcasterï¼388æ¯éè¦æååºæ¥ç
æ¹ä¸ä¸æ£åå¼å°±å¯ä»¥äº.
æ
pattern=r'.*(numberlocation)/\.(NumberLocationActivity).*\+(.*)ms'æ¹æ
pattern=r'.*\.(.*)/\.(.*).*\+(.*)ms'