Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to search string from right side .
For example =File be like file.c

content be like
if(a>10)
const char abc[] = {"NEL1.19"};

if(b>10)
const char abc[] = {"LME1.19"};



In my file abc[] is more than one time.if I find the string using abc[] it update the last abc[] in the file.so I thought to serach half string {"NEL1. from right side . then try to update the value by 1

What I have tried:

@Echo on

    Cd /d D:\
	setlocal enabledelayedexpansion
	set "file=newabc.c"
	
	for /F "tokens=1,* delims==" %%i in ('findstr " = {"NEL1.*"   " newabc.c') do (
	::{"*BLM1.*" xyz.c')
    set "versionVar=%%~i"
    set "versionVal=%%~j"
	echo %versionVal%
	set demo=%versionval:~7,5%
	set check=%demo:~0,-3%
	echo %check%
	::set "string=!versionVal:~2,5!"
	set /a sequence=!check!+1
	echo %sequence%
	)

	for /f "tokens=1,*delims=]" %%i in ('type "%file%" ^| find /v /n "" ^& break^>%file%') do (
    set "line=%%j"
    if "!line!" == "!versionVar!=!versionVal!" set line=!versionVar!= !sequence!
    echo(!line!>>!file!
	
	)
pause
Posted
Updated 14-Nov-22 16:07pm
v2
Comments
OriginalGriff 14-Nov-22 2:17am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
RickZeeland 14-Nov-22 3:10am    
As you have been struggling with batch files for some time now, maybe you should consider another approach, batch files are not really suitable for what you want.
I would recommend using C#, VB.NET or PowerShell, as .NET makes these kind of things much easier.
Radha sharma 2022 14-Nov-22 4:07am    
@RickZeeland,I am new for batch file thatswhy I am facing issues like that. This is the last issue. If you have any solution please help me out from this issue.
RickZeeland 14-Nov-22 4:37am    
Guess it's easy for me to say, as I have enough experience with both batch files and .NET
:)

1 solution

As I am rusty with windows/dos batch files, I did a google search: windows batch file pattern matching - Google Search[^]

This looks like what you may be looking for: File name pattern matching in Windows command line[^]

Digging a bit deeper: findstr examples - Google Search[^]

Found this: MS-DOS and Windows command line findstr command[^]
 
Share this answer
 
Comments
Radha sharma 2022 15-Nov-22 1:50am    
@Graeme_Grant, Thanks it work for me.
Graeme_Grant 15-Nov-22 2:14am    
You are most welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900