我在目录中有999,999个文件:member.php\?1member.php\?2...member.php\?99999我想在特定文件的bash或python循环中运行以下cat命令.该命令应该从.php文件中提取用户名,但由于涉及大量文件,因此无法使用.root@alimp5:...

我在目录中有999,999个文件:
member.php\?1
member.php\?2
...
member.php\?99999
我想在特定文件的bash或python循环中运行以下cat命令.该命令应该从.php文件中提取用户名,但由于涉及大量文件,因此无法使用.
root@alimp5: cat member.php\?* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1 >> users.txt
我的解决方案(这种方式很好用):在每个文件上逐步执行上述cat命令,如下所示:
root@alimp5:cat member.php\?1* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1 >> users.txt
root@alimp5:cat member.php\?2* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1 >> users.txt
...
root@alimp5:cat member.php\?9* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1 >> users.txt
我想通过在python循环或bash循环中运行上述解决方案来使其自动化.
例如(无效):
import os, sys
for count in range(1,10):
os.system('''cat member.php\?%d* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1 >> users.txt''') %count
什么是这样做的好方法?
解决方法:
在python命令中,您做错了,%计数应在os.system()调用内.范例-
os.system('''cat member.php\?%d* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1 >> users.txt''' % count)
另外,您应该迭代直到所需的数量.
沃梦达教程
本文标题为:在python或bash循环中运行linux cat命令


基础教程推荐
猜你喜欢
- python的环境conda简介 2022-10-20
- CentOS7 安装 Python3.6 2023-09-04
- Python数据提取-lxml模块 2023-08-11
- windows下安装python requests 2023-09-05
- 基于Python实现评论区抽奖功能详解 2023-08-09
- python之进程池和线程池 2023-09-03
- 解析django的csrf跨站请求伪造 2022-08-30
- 基于Python实现电影售票系统 2023-08-11
- python线程池/进程池创建 2023-09-04
- PYTHON-进程 子进程 2023-09-03