I am trying to make a batch file to execute a few things for me.
Now I do understand a few programming languages, but I haven\'t done much in batch file programming yet.
If you simply want to output the matching line with no logic checking, do
findstr /i "node" "%file1%"
If you want to execute some code if the line is found, use conditional execution.
findstr /i "node" "%file1%" && (
rem File contained "node". Do some stuff.
) || (
rem File did not contain "node". Do something else.
)
And if you want to use findstr
to test for the existence of a string without actually dumping the result to the console, simply add >NUL
either before or after the findstr
command.
>NUL findstr /i "node" "%file1%" && (success) || fail
If you are new to scripting, I would avoid batch (shell script) and use PowerShell. PowerShell is far more powerful and flexible.
get-content 'file.txt' | select-string 'node:(\s+)' | foreach-object {
$_.Matches[0].Groups[1].Value
}
This command would output the first substring match (from inside parentheses in regular expression) from each line.