I need to find text in a file when I open it with Notepad++.
For instance I need to find the text "ABC". However the true text I need are 2 numbers that follow "ABC". So I have a batch file that uses Notepad++ to open a particular file when I double click it. It needs to find ABC and then look at the 2 digits directly following it and populate a variable with them.
Some files might contain ABC12 while others might contain ABC21, etc.
All I have so far is the following:
%echo off
"C:\Program Files (x86)\Notepad++\notepad++.exe" %1
FIND [/I] "ABC"
It opens the file fine, but does not search. Please help!
Thanks!
this is a really nice question! Try this:
@ECHO OFF &SETLOCAL
set "LineNr="
for /f "tokens=1*delims=[]" %%a in ('^<"%~1" find /i /n "%~2"') do if not defined LineNr (
set "LineNr=%%a"
SET "Line=%%b"
)
if not defined LineNr (
set "LineNr=1"
SET "Row=1"
GOTO :launch
)
CALL SET "Right=%~2%%Line:*%~2=%%"
CALL SET "Line=%%Line:%Right%=%%"
FOR /f "delims=:" %%a in ('"(echo("%Line%"&@echo()|findstr /o $"') do SET /a Row=%%a-4
:launch
START /b CMD /c ""%ProgramFiles(x86)%\Notepad++\notepad++.exe" -n%LineNr% -c%Row% "%~1""
calling the batch:
script.bat "D:\PATH\FILE.TXT" "STRING TO SEARCH"
notepad++ command line switches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With