Re: [問題] 過掉檔案某行數已刪文
如果有一台 Unix 或 Linux 的主機在手邊
用 grep 應該是最簡單的
$ grep "^\d" file
或者,用 Perl one-liner,長一點點
$ perl -ne 'print if /^\d/;' file
如果要用 Python,可能是像這樣子
import re
f = 'file'
with open(f, 'r') as f:
for line in f:
if re.match(r'\d', line):
print line, # , for tailed "\n"
要注意 re.match 一定要從字串開頭開始算,否則請改用 re.search
參考看看
※ 引述《yshihyu (yshihyu)》之銘言:
: https://gist.github.com/anonymous/be9247e9a5c63687e894
: 上面是原始資料 我想保留下面這樣數字格式
: https://gist.github.com/anonymous/62875442c02d1920a06f
: 有什麼方便比較簡單可以濾過掉那些行數?
: 謝謝
--
Happy Computing - Tips and recipes for Unix and programming
http://cwchen123.tw/
Follow me at Twitter
https://twitter.com/cwchen123
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 203.71.94.31
※ 文章網址: http://www.ptt.cc/bbs/Python/M.1411809805.A.E06.html
※ 編輯: Neisseria (203.71.94.31), 09/27/2014 17:25:27
→
09/27 22:54, , 1F
09/27 22:54, 1F
→
09/28 00:48, , 2F
09/28 00:48, 2F
→
09/28 00:49, , 3F
09/28 00:49, 3F
推
09/28 04:12, , 4F
09/28 04:12, 4F
Python 近期熱門文章
PTT數位生活區 即時熱門文章