0

I am looking for adding array or multiple searches in the Find command of cmd but as soon i tried it do nothing following command worked fine with one input.

For one Input:

Find /V "/1001214955/" Scan-FtpOut.txt > Ftp_New.txt

For multiple inputs:

Find /V "/1001214955/ | /WENP/ " Scan-FtpOut.txt > Ftp_New.txt
Find /V "/1001214955/ -o /WENP/" Scan-FtpOut.txt > Ftp_New.txt

nothing is working please assist.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • `Find` can only search for one string. You can use it's successor `findstr /?` instead. – Stephan Dec 29 '21 at 13:26
  • Please open a Command Prompt window, type `%SystemRoot%\System32\findstr.exe /?`, and press the `[ENTER]` key to read its syntax and usage information. You could then try, for example: `@%SystemRoot%\System32\findstr.exe /R /V "\/1001214955\/ \/WENP\/" "Scan-FtpOut.txt" 1>"Ftp_New.txt"` and/or `@%SystemRoot%\System32\findstr.exe /R /V "[/]1001214955[/] [/]WENP[/]" "Scan-FtpOut.txt" 1>"Ftp_New.txt"` and/or `@%SystemRoot%\System32\findstr.exe /L /V /C:"/1001214955/" /C:"/WENP/" "Scan-FtpOut.txt" 1>"Ftp_New.txt"`. Then `Type "Ftp_New.txt"` to see if it worked as you needed. – Compo Dec 29 '21 at 14:22
  • none of these commands worked either -Compo – Sheikh_Sheharyar Dec 29 '21 at 14:53
  • Well you must not have used the same information as you submitted in your question, and for which I provided examples in my comment above! I have given you three examples all of which will result in a file containing all lines from `Scan-FtpOut.txt` which do not contain the exact string `/1001214955/` and the exact case sensitive string `/WENP/`. If you are testing with other strings, then that is outside of the scope of my examples, and requires that you better understand the usage information, I told you how to access. – Compo Dec 29 '21 at 15:13

3 Answers3

0

do it with 2 commands

Find /V "/1001214955/ | /WENP/ " Scan-FtpOut.txt > Ftp_New.txt send {Enter}

Find /V "/1001214955/ -o /WENP/" Scan-FtpOut.txt > Ftp_New.txt send {Enter}

Emma Marshall
  • 354
  • 1
  • 12
  • Have done this already but these commands even do nothing, matching string remains in the input_file. – Sheikh_Sheharyar Dec 29 '21 at 13:28
  • /v argument display all lines that don't contain the specified string being search perhaps you got your argument mixed up https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/find – Emma Marshall Dec 29 '21 at 13:46
  • what I am trying removing "1001214955" and "WENP" from input files and want the rest of all in the output file. First command working absolutely fine with one input not more than 1 – Sheikh_Sheharyar Dec 29 '21 at 13:50
0

As a follow up to my comment, and to show you that my commented commands work exactly as given, (to remove all lines within Scan-FtpOut.txt which contain the exact string /1001214955/ or which contain the exact case sensitive string /WENP/, and output those to Ftp_New.txt).

Here is an example Scan-FtpOut.txt file:

      200 PORT command successful.
      150 Opening data connection for /WENP/Faketest (467 bytes).
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec.

      200 PORT command successful.
      150 Opening data connection for /1001214955/Faketest (467 bytes).
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec.

Here are the contents of Ftp_New.txt after running @%SystemRoot%\System32\findstr.exe /R /V "\/1001214955\/ \/WENP\/" "Scan-FtpOut.txt" 1>"Ftp_New.txt":

      200 PORT command successful.
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec.

      200 PORT command successful.
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec.

Here are the contents of Ftp_New.txt after running @%SystemRoot%\System32\findstr.exe /R /V "[/]1001214955[/] [/]WENP[/]" "Scan-FtpOut.txt" 1>"Ftp_New.txt":

      200 PORT command successful.
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec.

      200 PORT command successful.
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec

Here are the contents of Ftp_New.txt after running @%SystemRoot%\System32\findstr.exe /L /V /C:"/1001214955/" /C:"/WENP/" "Scan-FtpOut.txt" 1>"Ftp_New.txt":

      200 PORT command successful.
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec.

      200 PORT command successful.
      226 Transfer complete.
      467 bytes transferred in 2.845 seconds. Transfer rate 0.167KB/sec

As you can see the results of each of my initially offered commands show exactly the intended results!

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Compo Thanks ! I tried one of your commands, the issue was occurring I figure that out as well findstr /L /V /C:"/1001214955/" /C:"/WENP/" "Scan_FtpOut.txt" 1>"Ftp_New.txt" – Sheikh_Sheharyar Dec 29 '21 at 21:14
  • @Sheikh_Sheharyar, please clarify what you mean by "the issue was occurring". You can clearly see that all three commands return the correct results without issue. An issue would therefore only occur if you changed something. My answer does not require changing, if your question changes, that is irrelevant to the asked question, and it would therefore be necessary for you to make the changes you should have read and understood from the output of `%SystemRoot%\System32\findstr.exe /?`, _(which i specifically directed you to earlier)_. – Compo Dec 30 '21 at 00:16
  • your answer is absolutely right the issue occurring in the file where i need to apply this command i have to copy the content of file to another then it is working, might be some sort of glitch otherwise all going smooth. – Sheikh_Sheharyar Dec 30 '21 at 05:03
0

The PowerShell that is available on all supported Windows systems has a much more complete implementation of regex than does findstr.exe. Using a PowerShell regex means you can use the many sources of regex information available on the net.

Based on https://stackoverflow.com/a/7801667/447901, here is how it could be done in a [cmd] script or command.

powershell.exe -NoLogo -NoProfile -Command ^
    "(Select-String -Pattern '^(?!.*(/1001214955/|/WENP/)).*$' -Path .\Scan-FtpOut.txt).Line >'.\Scan-FtpOut-New.txt'"

It would be less convoluted and more easily understood if the script is written in [powershell] and not [cmd].

lit
  • 14,456
  • 10
  • 65
  • 119