Hi, I want to use "find" command to count the number of lines containing the string in a text file. The command is pretty straightforward.
My question is that can I save the result to a variable?
Because I am going to use it in microsoft .net application.
Thanks
Set a variable
Moderator: DosItHelp
Re: Set a variable
Try this line:
The number of lines should be in %var% now.
But do you realy mean it is a good idea to use this in .net?
Regards
aGerman
Code: Select all
for /f "tokens=2,3 delims=:" %%i in ('find /c "SearchString" "file.ext"') do if "%%j"=="" (set /a var=%%i) else set /a var=%%j
The number of lines should be in %var% now.
But do you realy mean it is a good idea to use this in .net?
Regards
aGerman
Re: Set a variable
I want to introduce it in a console application.
The lines is the number of lines. I use the code like
I don't know how to combine your code with my snippet.
Code: Select all
Console.Write("Count"+lines);
The lines is the number of lines. I use the code like
Code: Select all
Process test = new Process();
test.StartInfo.FileName = "cmd";
test.StartInfo.Arguments = @....
I don't know how to combine your code with my snippet.
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: Set a variable
This is how to run CMD and pass code as an argument:
cmd /c terminates cmd after the code. cmd /k keeps cmd running after the code.
Code: Select all
cmd /c for /f "tokens=2,3 delims=:" %%i in ('find /c "SearchString" "file.ext"') do if "%%j"=="" (set /a var=%%i) else set /a var=%%j
cmd /c terminates cmd after the code. cmd /k keeps cmd running after the code.