Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run linux cat command in python or bash loop

i have 999,999 files in a directory:

member.php\?1

member.php\?2

...

member.php\?99999

I want to run the below cat commands in bash or python loop on specific files. This command is supposed to extract usernames from .php files, but doesn't work because of the large number of files involved.

root@alimp5: cat member.php\?* | grep -i '<li class="navbit lastnavbit"><span>' | cut -d'>' -f3 | cut -d'<' -f1  >> users.txt

My solution (this way works fine): execute above cat command step by step on each file as follows:

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

I want to automate the above solution by running it in a python loop or a bash loop.

For example (doesn't work):

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

What is a good way to do this?

like image 312
ali reza Avatar asked Nov 19 '25 07:11

ali reza


1 Answers

#!/bin/bash
for i in {1...9999999}
do
   $i 
done

Now you just add the $i next to the command you pretend

'cat member.php\?$i
like image 109
Bruno Caceiro Avatar answered Nov 20 '25 20:11

Bruno Caceiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!