Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Usinf CMD line for advanced search.  (Read 7317 times)

0 Members and 1 Guest are viewing this topic.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Usinf CMD line for advanced search.
« on: September 20, 2017, 04:32:09 PM »
The standard search in Windows, apparently, has few options of AND with NOT.
Correct me if I am wrong.
Problem: I think I have TXT files somewhere with old e-mails address. But I am not sure. If I had a perfect memory, I would not need a computer.
Le's same my name is Gordan, it is not, and and my e-mail might have been  ymail.com
I know I have files with [email protected], but I want to see if there were any other user names I had used on ymail in the past year..
So, I want to find all text files that have:

Code: [Select]
@ymail.com AND NOT [email protected]
How can I do that from the command line?

Either in Windows XP or Windows 7.

Thank you all.  :)

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Usinf CMD line for advanced search.
« Reply #1 on: September 20, 2017, 07:51:53 PM »
I have just used notepad to open file and then use the FIND function in text files to find content. If the file is too big for notepad I have opened it using Word and then use FIND in which for an e-mail I would think all you would need to search for is @ as for it probably has no other purpose in whatever files you have. If you have multiple files and not which which ones have @ in them then you would likely want to use a search for the @ symbol in files and then flag which files have a @ in them. Then use notepad or word with those files that were positive detections for @ sign in them. And use the FIND function to show all matches to @ symbol in the file in which if there are e-mail addresses then it should show all of them.

One thing you could do is get all of your text files piled into a known location such as connect a thumb drive if the thumb drive is at E: run xcopy c:\*.txt e:\TextFiles\*.* /s/h/y and then you will have all known text file locations copied to TextFiles folder you then can navigate through and figure out which files are just readme or log files from files you created that might contain e-mail addresses and search those for @

Salmon Trout

  • Guest
Re: Usinf CMD line for advanced search.
« Reply #2 on: September 21, 2017, 01:54:53 PM »
Agent Ransack has Boolean search. It's very useful, fast and free, (and it's British!) and works on Vista and later. Click the image to make it bigger.

https://www.mythicsoft.com/agentransack/download





Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Usinf CMD line for advanced search.
« Reply #3 on: September 21, 2017, 03:45:07 PM »
Thanks, That is want I need.  8)
BTW: For Windows XP you need to find the older version of 2014.
Old Version Agent Ransack

The current version is for Vista and up.  :D

Salmon Trout

  • Guest
Re: Usinf CMD line for advanced search.
« Reply #4 on: September 21, 2017, 03:50:23 PM »
It can add itself to the right-click context menu in Windows Explorer, and you can also run it from the command line.

Hackoo



    Hopeful
  • Thanked: 42
  • Experience: Expert
  • OS: Windows 10
Re: Usinf CMD line for advanced search.
« Reply #5 on: September 22, 2017, 04:29:51 AM »
Hi  ;)
I just modified my old script to search only on text files ( The Original script can be found here https://pastebin.com/raw/ADdjPEfH )
So, just give a try and tell how it works on your side  ;D
Code: [Select]
@ECHO OFF
REM The Original script can be found here https://pastebin.com/raw/ADdjPEfH
Rem This is a modified version to search only on text files
Title Scan a folder and Search a string in multi-files by (c) Hackoo 2017
mode 78,2
Call :init
Call :inputbox "Please enter something to search :" "Search a string in multi-files by (c) Hackoo 2017"
If  "%input%" == ""  Color 0C & (
echo(
echo           You must enter a string to continue with this program
pause>nul & exit
) else (
Call :BrowseForFolder "Please Choose source folder to scan for %input%" SourceFolder
    Setlocal EnableDelayedExpansion
    If defined SourceFolder (
        echo(
        echo             You chose "!SourceFolder!" as source folder & pause
    ) else (
        echo(
        Color 0C & echo                    The source folder is not defined ... Exiting ......
        Timeout /T 2 /nobreak>nul & exit
    )
)
::******************************************************************************************
Set "ROOT=%SourceFolder%"
::Does string have a trailing back slash ? if yes, so, we remove it !
IF %ROOT:~-1%==\ SET ROOT=%ROOT:~0,-1%
Rem you can add also those extensions txt vbs js json hta php htm html xml csv rtf
SET "EXT=txt"
SET "Count=0"
set "Word2Search=%input%"
Set "NewFolder2Copy=%userprofile%\Desktop\CopyFiles_%Word2Search%"
Set "LogFile=%~dp0%~n0_%Word2Search%.txt"
SETLOCAL enabledelayedexpansion
REM Iterates throw the files on this current folder and its subfolders.
REM And Populate the array with existent files in this folder and its subfolders
For %%a in (%EXT%) Do (
Call :Scanning "%Word2Search%" "*.%%a"
Call :PS_Sub 'information' 10 '"Scanning now for """%Word2Search%""" on """*.%%a""" . . . "' "'Please wait. . . Scan is in progress on all """*.%%a""" . . .'" 'info' 5
FOR /f "delims=" %%f IN ('dir /b /s "%ROOT%\*.%%a"') DO (
( find /I "%Word2Search%" "%%f" >nul 2>&1 ) && (
SET /a "Count+=1"
set "list[!Count!]=%%~nxf"
set "listpath[!Count!]=%%~dpFf"
)
) || (
( Call :Scanning "%Word2Search%" "%%~nxf" )
)
)
::*******************************************************************
:Display_Results
cls & color 0B
echo wscript.echo Len("%ROOT%"^) + 20 >"%tmp%\length.vbs"
for /f %%a in ('Cscript /nologo "%tmp%\length.vbs"') do ( set "cols=%%a")
If %cols% LSS 50 set /a cols=%cols% + 28
rem If %cols% LSS 50 set /a cols=%cols% + 15
set /a lines=%Count% + 17
Mode con cols=%cols% lines=%lines%
echo(
Call :color 0A " ------------------------------------------------" 1
ECHO   Folder : "%ROOT%"
Call :color 0A " ------------------------------------------------" 1
rem If Exist "%LogFile%" Del "%LogFile%"
rem Display array elements
for /L %%i in (1,1,%Count%) do (
set "msg=[%%i] - !list[%%i]!"
echo !msg!
)
ECHO(
ECHO Total of [%EXT%] files(s) that contains
Echo the string "%Word2Search%" is : %Count% file(s)
echo.
Call :color 0D "Type the number of file that you want to explore" 1
echo(
Call :color 0C "To save results into a LogFile just type 'LOG'" 1
echo(
Call :color 0A "To copy all files found just type 'Copy'" 1
set /p "Input="
For /L %%i in (1,1,%Count%) Do (
    If "%INPUT%" EQU "%%i" (
        Call :Explorer "!listpath[%%i]!"
    )
IF /I "%INPUT%"=="Log" (
Call :Save_Results
)
IF /I "%INPUT%"=="Copy" (
Call :CopyFiles
)
)   
Goto:Display_Results
::****************************************************************************
:Save_Results
If Exist "%LogFile%" Del "%LogFile%"
rem Display array elements and save results into the LogFile
(
Echo   ------------------------------------------------
ECHO   Folder : "%ROOT%"
echo   ------------------------------------------------
)>"%LogFile%"

for /L %%i in (1,1,%Count%) do (
set "msg=[%%i] - !list[%%i]!"
echo !msg! -- "!listpath[%%i]!" >> "%LogFile%"
)

(
ECHO.
ECHO Total of [%EXT%] files(s^) : %Count% file(s^) that contains the string "%Word2Search%"
)>> "%LogFile%"
Start "" "%LogFile%"
Goto:Display_Results
::****************************************************************************
:Scanning <Word> <file>
mode 78,3
Cls & Color 0A
echo(
echo      Scanning for the string "%~1" on "%~2" ...
goto :eof
::****************************************************************************
:Explorer <file>
explorer.exe /e,/select,"%~1"
Goto :EOF
::****************************************************************************
:init
prompt $g
for /F "delims=." %%a in ('"prompt $H. & for %%b in (1) do rem"') do set "BS=%%a"
exit /b
::****************************************************************************
:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
    <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
    echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)
exit /b
::***************************************************************************
:BrowseForFolder
set "psCommand="(new-object -COM 'Shell.Application')^
.BrowseForFolder(0,'%1',0,0).self.path""
for /f "usebackq delims=" %%I in (`powershell %psCommand%`) do set "%2=%%I"
exit /b
::***************************************************************************
:InputBox
set "input="
set "heading=%~2"
set "message=%~1"
echo wscript.echo inputbox(WScript.Arguments(0),WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do (
set "input=%%a"
)
exit /b
::***************************************************************************
:PS_Sub $notifyicon $time $title $text $icon $Timeout
PowerShell  ^
  [reflection.assembly]::loadwithpartialname('System.Windows.Forms') ^| Out-Null; ^
 [reflection.assembly]::loadwithpartialname('System.Drawing') ^| Out-Null; ^
 $notify = new-object system.windows.forms.notifyicon; ^
  $notify.icon = [System.Drawing.SystemIcons]::%1; ^
  $notify.visible = $true; ^
  $notify.showballoontip(%2,%3,%4,%5); ^
  Start-Sleep -s %6; ^
  $notify.Dispose()
%End PowerShell%
exit /B
::****************************************************************************
:MakeCopy <Source> <Target>
If Not Exist "%~2\" MD "%~2\"
Copy /Y "%~1" "%~2\"
goto :eof
::****************************************************************************
:CopyFiles
cls
mode con cols=80 lines=20
for /L %%i in (1,1,%Count%) do (
echo Copying "!list[%%i]!" "%NewFolder2Copy%\"
Call :MakeCopy "!listpath[%%i]!" "%NewFolder2Copy%">nul 2>&1
)
Call :Explorer "%NewFolder2Copy%\"
Goto:Display_Results
::*****************************************************************************

[attachment deleted by admin to conserve space]

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Usinf CMD line for advanced search.
« Reply #6 on: September 22, 2017, 11:30:36 AM »
Thanks for sharing Hackoo ... gonna have to try out your batch tonight on my home pc. Looks interesting. Also Salmon shared the Agent Ransack method and I forgot that that has a search feature for ascii/string data. I use Agent Ransack because Windows 7 doesnt have a good built in search feature like XP had. Someone here suggested Agent Ransack as a search for Windows 7 and ever since then, I have used it when looking for file names, but haven't used it to find files with matching text etc.

Salmon Trout

  • Guest
Re: Usinf CMD line for advanced search.
« Reply #7 on: September 23, 2017, 03:46:05 AM »
I needed to find a batch file I made in 2013 in which I tried out the Agent Ransack command line interface, and guess what I used? (click to enlarge)



You can script Agent Ransack in a batch or even from the prompt, if you are bored...

Code: [Select]
C:\Batch\Ransack-Test>type My2.txt
apple
pear
dog


Code: [Select]
C:\Batch\Ransack-Test>"C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe" -o "%cd%\ransack.rky" -oea -ofc -f "M*.txt" -c "dog AND apple" -dw

C:\Batch\Ransack-Test>type ransack.rky
C:\Batch\Ransack-Test\,My2.txt,1 KB,TXT File,23/09/2017 09:48:37,23/09/2017 09:48:37,23/09/2017 09:48:37,2,1,apple
C:\Batch\Ransack-Test\,My2.txt,1 KB,TXT File,23/09/2017 09:48:37,23/09/2017 09:48:37,23/09/2017 09:48:37,2,3,dog

Full documentation at the Agent Ransack site.

One thing I noticed is that my 2013 version of Agent Ransack defaulted to ASCII text output, whereas my current version - Release Build 867 - 2017.03.02.44979 (x64) - seems to default to UTF-8 - it started the output file with a three-byte UTF-8 Byte Order Marker (BOM) (that is, these bytes: EF BB BF) unless I expliclty specified ASCII output with the -oea option as you see above.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Usinf CMD line for advanced search.
« Reply #8 on: September 23, 2017, 09:53:18 AM »
So, the best answer is Agent Ransack .
It is both a Visual and a command tool for finding stuff.
In Windows XP in have to stick to the 2014 version. But Windows 7 and up can use the current version.

All you people out there with Windows 7, get Agent Ransack and use in in place of the windows search tool.

Salmon Trout, great job!  :)

Salmon Trout

  • Guest
Re: Usinf CMD line for advanced search.
« Reply #9 on: September 23, 2017, 12:48:26 PM »
Code: [Select]
D:\searchtest>type g1.txt
[email protected]
D:\searchtest>type g2.txt
[email protected]

AR.bat

Code: [Select]
@echo off
REM Quick hack for Agent Ransack
REM Read the docs!
REM Play around!
if "%1"=="" (
echo Agent Ransack runner batch
echo usage:
echo Params 1 to 3 required, 4 is optional
echo 1 is files to search e.g. *.txt
echo 2 is text to find e.g. "foo" "foo NOT bar"
echo   Booleans are in CAPITALS
echo 3 is folder to start
echo 4 -s to recurse, omit for no recurse
echo example ar.bat "*.*" "@ymail.com NOT Billy" "%cd%" "-s"
goto end
)
REM see docs for explanation of options.
REM Some of the File Locator Pro options work
REM Agent Ransack GUI will not look in zip archives,
REM CLI will, but some oddities in output
REM May still be usable. Try it & see
set ofile=%temp%\arout.txt
if exist "%ofile%" del "%ofile%"
"C:\Program Files\Mythicsoft\Agent Ransack\AgentRansack.exe" -o "%ofile%" %~4 -oea -ofc -ceb -f "%~1" -c "%~2" -d "%~3" && type "%ofile%"
:end

Code: [Select]
D:\searchtest>AR.bat "*.txt" "@ymail.com" "D:\searchtest"
D:\searchtest\,g1.txt,1 KB,TXT File,21/09/2017 20:46:57,23/09/2017 15:27:23,23/09/2017 15:27:23,1,1,[email protected]
D:\searchtest\,g2.txt,1 KB,TXT File,21/09/2017 19:47:39,23/09/2017 15:27:23,23/09/2017 15:27:23,1,1,[email protected]
D:\searchtest>AR.bat "*.txt" "@ymail.com NOT Gordon" "D:\searchtest"
D:\searchtest\,g2.txt,1 KB,TXT File,21/09/2017 19:47:39,23/09/2017 15:27:23,23/09/2017 15:27:23,1,1,[email protected]
D:\searchtest>AR.bat "*.txt" "@ymail.com NOT Billy" "D:\searchtest"
D:\searchtest\,g1.txt,1 KB,TXT File,21/09/2017 20:46:57,23/09/2017 15:27:23,23/09/2017 15:27:23,1,1,[email protected]

Salmon Trout

  • Guest
Re: Usinf CMD line for advanced search.
« Reply #10 on: September 23, 2017, 03:48:07 PM »
Quote
D:\searchtest\,g1.txt,1 KB,TXT File,21/09/2017 20:46:57,23/09/2017 15:27:23,23/09/2017 15:27:23,1,1,[email protected]

Column headings

Path, Filename, Size, Type, Modified date, Created date, Last accessed, Hit Count, Line number, Line text