分页: 1 / 1
[已解决]怎么删去数据中只包括'0'的行
发表于 : 2012-03-24 13:02
由 guang3000
最近要处理几千行的数据,要删除里面含有一些只有字符0的行,例如下面数据
0.7192
0.7104
0
0.7123
0.7024
0.6999
0
0.6984
0.7223
0.7129
0.6721
但是其它行的数据也包含字符'0'。该怎么操作才能不影响其它数据啊,
请高手指点下菜鸟,不胜感激!
Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 13:14
由 lilydjwg
Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 13:16
由 枫叶饭团
代码: 全选
[maplebeats@maplebeats python]$ cat word
0.7192
0.7104
0
0.7123
0.7024
0.6999
0
0.6984
0.7223
0.7129
0.6721
[maplebeats@maplebeats python]$ python3 file.py word
[maplebeats@maplebeats python]$ cat word
0.7192
0.7104
0.7123
0.7024
0.6999
0.6984
0.7223
0.7129
0.6721
[maplebeats@maplebeats python]$
[python]#!/usr/bin/env python3
import fileinput
for line in fileinput.input(inplace=1):
line = line.rstrip()
if(line != '0'):
print (line)
[/python]
Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 13:17
由 枫叶饭团
哈哈,我觉得我的方法很SB

Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 13:27
由 lilydjwg
shell 版本:
代码: 全选
sed -i '/^0$/d' files
Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 13:42
由 老蒋
Emacs
[lisp]C-home M-x flush-line ^0$[/lisp]
Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 14:05
由 daf3707
脚本党大显身手
Re: 求助,怎么删去数据中只包括'0'的行(急)
发表于 : 2012-03-24 14:38
由 guang3000