.. findstr

intro

introduction à "findstr" (DOS), pour replacer "grep" (unix)
pas parfait (bug, lenteur) mais mieux que FIND

créer un alias: doskey grep=findstr $*
:-)

easy

findstr                  word1 file
findstr        /C:"word1 word2" file
findstr    /S  /C:"word1 word2" file
           + subdir
findstr -I     /C:"word1 word2" file
         ignore up/low
findstr /I /S  /C:"word1 word2" file
      + ignore up/low


     
H:\ADMIN> findstr  bunk *.htm
adhoc.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> ...
H:\ADMIN> findstr daily *.htm *.txt
gmp.htm:xxxx daily xxx cifprod_tty.txt:xxxx daily xxx ...
H:\ADMIN> findstr bunk *.htm
adhoc.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> ...
search in 2 files extension H:\ADMIN> findstr daily *.htm *.txt
gmp.htm:xxxx daily xxx cifprod_tty.txt:xxxx daily xxx ...
AND H:\ADMIN> findstr /c:"partition auth fail" hsm* AND up+low H:\ADMIN> findstr -i /c:"partition auth fail" hsm*
hsm.htm: Partition Auth Fail Limit: 5 hsm.htm: Partition Auth Fail Action: 0 (lock) hsm.htm: Partition Auth Fail Limit: 5 hsm2014.htm: Partition Auth Fail Action: 0 (lock) hsm2014.htm: Partition Auth Fail Limit: 5 hsm2014.htm: Partition Auth Fail Action: 0 (lock) hsm2014.htm: Partition Auth Fail Limit: 5
OR up+low H:\ADMIN> findstr -i "partition auth fail" hsm*
hsm201202err:NTLS/SSL TCP Connectivity: FAILED hsm201202err:HSM Partition Activation Status: PASSED hsm201202err:Failed Group Logins: 0 hsm201202err:Partitions Total: 250 hsm2014.htm:Successfully unlocked partition HSM1:bkbbc hsm2018.htm:SO Auth Fail Count: 0 hsm2018.htm:SO Auth Fail Limit: 0 hsm2018.htm:SO Auth Fail Action: 0 (zeroize) hsm2018.htm:Partition Auth Fail Limit: 3
H:\ADMIN> findstr /i /c:"partition fail" hsm* nothing

more


2 finds (= pipe):
H:\ADMIN> findstr  _bunk0 *.htm | findstr cle|sort
bank.htm:<img src="IMG/_bunk0.gif" alt="BC"> <img src="IMG/cle_logo0.png" alt="BC"><br> cle.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> gmp_24.htm:<img src="IMG/_bunk0.gif" alt="BC"> <img src="IMG/cle_logo0.png" alt="BC"><br> gmp_247.htm:<img src="IMG/_bunk0.gif" alt="BC"> <img src="IMG/cle_logo0.png" alt="BC"><br> gmp_sic.htm:<img src="IMG/_bunk0.gif" alt="BC"> <img src="IMG/cle_logo0.png" alt="BC"><br>
(*) cle.htm = error!! sort: H:\ADMIN> findstr _bunk0 *.htm | findstr "alt=\"\"" |sort
adhoc.htm:<img src="IMG/_bunk0.gif" alt=""><br> adsm.htm:<img src="IMG/_bunk0.gif" alt=""><br> afp.htm:<img src="IMG/_bunk0.gif" alt=""><br> ...
count: H:\ADMIN> findstr _bunk0 *.htm | findstr "alt=\"\"" |find /c "alt"
448
H:\ADMIN> findstr _bunk0 *.htm | findstr "alt=\"BC\"" |find /c "alt"
88
special char: H:\ADMIN> findstr _bunk0 *.htm | findstr "alt=\"BC\""
igt2000.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> trxtest.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> hsm.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> hard.htm:<img src="IMG/_bunk0.gif" alt="BC"><br> ...

unix

si l'on cherche plus puissant... (je passe par l'ubuntu de mon W10)
= recherche dans des répertoires (vtt2019, vtt2020, vtt2021...)

 # find . -wholename "./vtt*/*.htm"
 # find . -wholename "./vtt*/*.htm"  -exec grep utf-8 {} \; -print
 
 # find . -wholename "./vtt*/*.htm"  -exec grep 'class="vtt"' {} \; -print
 # find . -wholename "./vtt*/*.htm"  -exec grep 'class="who"' {} \; -print
                      == important! (dans quel répertoire) 
on remplace "find -name ..." par "find -wholename ..."
ou
on remplace "find -path "?/vtt*/*" -name "*.htm"

Recherche des fichiers modifiés today + trié par datetime
$ find . -mtime 0 -printf "%T@ %Tc %p\n" | sort -n ... 1643300937.1883494000 Thu Jan 27 17:28:57 2022 ./ski/20200111realp.htm 1643301222.8497336000 Thu Jan 27 17:33:42 2022 ./ski/20170310.htm 1643301270.4795105000 Thu Jan 27 17:34:30 2022 ./ski/20220115winterhorn.htm 1643301270.4951395000 Thu Jan 27 17:34:30 2022 ./ski/20170211gaschney.htm 1643301270.5266460000 Thu Jan 27 17:34:30 2022 ./ski/201702barme.htm 1643301492.3455802000 Thu Jan 27 17:38:12 2022 ./ski/20201027engelberg.htm 1643301923.0898666000 Thu Jan 27 17:45:23 2022 ./ski/20190323.htm


Find (répertoire) + del si vide
[pam_cke@bs02-t ~]$ touch rr/1/7777 [pam_cke@bs02-t ~]$ find rr -type d -empty rr/2 rr/3 rr/45 rr/6 [pam_cke@bs02-t ~]$ find rr -type d -empty -delete [pam_cke@bs02-t ~]$ find rr -type d -empty [pam_cke@bs02-t ~]$ find rr -type d rr rr/1 [pam_cke@bs02-t ~]$ find rr -type f rr/1/7777 rr/4444
more info (YT)

win

SearchMyFiles.exe
nirsoft.net
installé sur H:/2023/SearchMyFiles

link

d'autres info dos.htm
en.wikipedia.org/wiki/Findstr
dir /od = ls -ltr