小编Ada*_*atz的帖子

grep -v 的 Python 等价物是什么?

我喜欢grep -v。我用它所有的时间。但我也在用 python 做一些文本处理,我缺少一件至关重要的事情。

通常,我grep -v习惯从文本中去除无关的东西。

例如,

$ grep -v '[a-z]'
# (I manually review this output to confirm that I don't want those lines)

$ grep '[a-z]' > linesiwanted
Run Code Online (Sandbox Code Playgroud)

但是如何在 Python 中匹配正则表达式的补码?例如,\w?

grep python text-processing regular-expression

17
推荐指数
1
解决办法
9万
查看次数

可靠地确定 BSD 中的可用内存

Linux 发行版倾向于(但不是必需的)包含freefrom procps,这可以很好地简洁地显示内存消耗:

# free -m
              total        used        free      shared  buff/cache   available
Mem:           7688        5027         180         827        2479        1589
Swap:          8189        2082        6106
Run Code Online (Sandbox Code Playgroud)

为了在 BSD 中近似这一点,我尝试了许多不同的项目,但它们都给了我不同的答案(大概是因为它们有不同的上下文?)。例如:

# sysctl -a |grep Memory
Virtual Memory:             (Total: 1077397132K, Active 3458308K)
Real Memory:                (Total: 1171952K Active 975744K)
Shared Virtual Memory:      (Total: 56264K Active: 38652K)
Shared Real Memory: (Total: 22184K Active: 19700K)
Free Memory Pages:  1664588K

# sysctl hw |awk '/mem:/ { printf "%s %.0fM\n", $1, $2/1024^2 }'
hw.physmem: 32756M …
Run Code Online (Sandbox Code Playgroud)

freebsd memory bsd top

12
推荐指数
1
解决办法
3776
查看次数

grep 用于一个或多个单词的出现

我想搜索 type 的出现。 super([A-Za-z]+ , self) 在代码库中。

当我 要向我$ grep -nr '[s][u][p][e][r][(]' .展示所有行时super(
当我尝试使用 [A-Za-z]+ 搜索以下行时,我没有得到任何结果。有人可以帮我搜索所有行吗在我的代码库super(*word* , self)中。

anupam:codebase-2.0$ grep -nr '[s][u][p][e][r][(][A-Za-z]+' .
anupam:codebase-2.0$ 
Run Code Online (Sandbox Code Playgroud)

grep

3
推荐指数
1
解决办法
6169
查看次数

标签 统计

grep ×2

bsd ×1

freebsd ×1

memory ×1

python ×1

regular-expression ×1

text-processing ×1

top ×1