在python或bash循环中运行linux cat命令

我在目录中有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命令

基础教程推荐