How to send the results of multiple Findstr commands to only one.txt file?

Asked

Viewed 33 times

0

I’m creating a which has several commands "Findstr"

How can I send the multiple results obtained by the commands "Findstr /i /c:Strings for the same arquivo.txt?

dir/s/b C:\Users > C:\Users\%username%\Desktop\SSHelpToolFiles.txt

findstr /i /C:"Click"  C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\ResultCLICK.txt
findstr /i /C:"Macro"  C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\MACRO.txt
findstr /i /C:"Client" C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\CLIENT.txt
findstr /i /C:"Hack"   C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\HACK.txt
findstr /i /C:"Reach"  C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\REACH.txt
findstr /i /C:"jnat"   C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\JNAT.txt

1 answer

1

You have options using redirectors > >>:

  • >Sobrescrever no arquivo
    • It will write in the file regardless of whether the file exists or not, in case there is no file, the redirector operator will create the file with the redirected content, in existing, the operator will replace the existing content in the file.
  • >>Acrescentar no arquivo:

    • Will write in the file regardless of whether the file exists or not, in case there is your file, the redirector operator will create the file with the redirected content, in existing, the operator will add the redirected content to the file.

You can send the result of multiple findstr to a text file?

  • >tem >>Sim!
dir/s/b C:\Users > C:\Users\%username%\Desktop\SSHelpToolFiles.txt

findstr /i /C:"Click"  C:\Users\%username%\Desktop\SSHelpToolFiles.txt >> C:\Users\%username%\Desktop\SSFileScanResult\MesmoArquivo.txt
findstr /i /C:"Macro"  C:\Users\%username%\Desktop\SSHelpToolFiles.txt >> C:\Users\%username%\Desktop\SSFileScanResult\MesmoArquivo.txt
findstr /i /C:"Client" C:\Users\%username%\Desktop\SSHelpToolFiles.txt >> C:\Users\%username%\Desktop\SSFileScanResult\MesmoArquivo.txt
findstr /i /C:"Hack"   C:\Users\%username%\Desktop\SSHelpToolFiles.txt >> C:\Users\%username%\Desktop\SSFileScanResult\MesmoArquivo.txt
findstr /i /C:"Reach"  C:\Users\%username%\Desktop\SSHelpToolFiles.txt >> C:\Users\%username%\Desktop\SSFileScanResult\MesmoArquivo.txt
findstr /i /C:"jnat"   C:\Users\%username%\Desktop\SSHelpToolFiles.txt >> C:\Users\%username%\Desktop\SSFileScanResult\MesmoArquivo.txt

+Note: 1. You can also use multiple strings in your command Findstr and to a single file in a single command:

dir/s/b "C:\Users" >"%UserProfile%\Desktop\SSHelpToolFiles.txt"
>"%UserProfile%\Desktop\SSFileScanResult\File.txt" %__AppDir__%findstr.exe /il "Click Macro Client Hack Reach jnat" "%UserProfile%\Desktop\SSHelpToolFiles.txt"

+Note: 2. If you don’t need to create the file "..\SSHelpToolFiles.txt", would be to get strings straight from the `dir command, thus writing/saving a file:

dir/s/b "C:\Users"| >"%UserProfile%\Desktop\SSFileScanResult\File.txt" %__AppDir__%findstr.exe /il "Click Macro Client Hack Reach jnat"  

+Note: 3. If you do not need to filter folder names, your command dir can restrict their listing with /a:-d (attribute -less directory).. , or use the command where /recursivo, where the exit with the complete path (equals dir /b), and applies only to files...

where /r "C:\Users" * | >"%UserProfile%\Desktop\File.txt" %__AppDir__%findstr.exe /il "Click Macro Client Hack Reach jnat"  

+Note: 4. Since your command is making use of a Windows environment variable (C:\User\%UserName%) to then compose the path in command, how about using something shorter (%UserProfile%)..

C:\Users\%username%\Desktop\SSHelpToolFiles.txt > C:\Users\%username%\Desktop\SSFileScanResult\ResultCLICK.txt
      %UserProfile%\Desktop\SSHelpToolFiles.txt > %UserProfile%\Desktop\SSFileScanResult\ResultCLICK.txt

+Note: 5. As a friend always says, "use quotes and have peace with yourself!"... avoid errors when using variables that may contain "compound name [spaces]"

 :: path\variável :: 
    %UserProfile%\Desktop\SSHelpToolFiles.txt
    C:\Users\%username%\Desktop\SSHelpToolFiles.txt 

:: "path\variável" ::
    "%UserProfile%\Desktop\SSHelpToolFiles.txt" 
    "C:\Users\%username%\Desktop\SSHelpToolFiles.txt" 

+Note: 6. There is also the option to use redirects by > blocos (de commandos)...

dir/s/b/a:-d "C:\Users" >"%UserProfile%\Desktop\SSHelpToolFiles.txt" && (
    findstr/iC:"Click"  "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"
    findstr/iC:"Macro"  "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"
    findstr/iC:"Client" "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"
    findstr/iC:"Hack"   "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"
    findstr/iC:"Reach"  "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"
    findstr/iC:"jnat"   "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"
    ) >"%UserProfile%\Desktop\Output_No_Mesmo_Arquivo.txt" 

rem :: ou... :: 
( where /r C:\Users * |findstr/iC:"Click" /iC:"Macro" /iC:"Client" /iC:"Hack" /iC:"Reach" /iC:"jnat"
) >"%UserProfile%\Desktop\Output_No_Mesmo_Arquivo.txt" "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"

rem :: ou... :: 
( where /r C:\Users * |findstr/il "Click Macro Client Hack Reach jnat"
) >"%UserProfile%\Desktop\Output_No_Mesmo_Arquivo.txt" "C:\Users\%username%\Desktop\SSHelpToolFiles.txt"

References and documentation for queries:

What are the undocumented features and limitations of the Windows FINDSTR command?

      ❖ in en     |    ❖ in-US

Help with the Findstr /?:

      ❖ in en     |    ❖ in-US

Supplementary consultations `// in en-US`:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.