I'm trying to see if there is a string that exists in a particular text file that I have. I already referred to this post but I'm having different issues.
I'm running this as a batch file in powershell with ./test.bat.
if [ "$(< C:/Temp/test.txt)" =~ "test" ]; then echo "true"
This returns "$(C:/Temp/test.txt)" was unexpected at this time.
I also tried
if grep -` "test" "$C:/Temp/test.txt"; then echo "True"
This returns -q was unexpected at this time.
What am I doing wrong?
findstr test c:\temp\test.txt >NUL && echo Trueis roughly the batch-file equivalent.@"%SystemRoot%\System32\find.exe" /I "test" 0<"C:\Temp\test.txt" 1>NUL 2>&1 && (Echo True) || Echo False, or for the case insensitive word:@"%SystemRoot%\System32\findstr.exe" /I /M /R "\<test\>" "C:\Temp\test.txt" 1>NUL 2>&1 && (Echo True) || Echo False.||as per example.findstr test "c:\temp\test.txt" >NUL && echo True || echo Falseor in the example where you also then want to exit.findstr test "c:\temp\test.txt" >NUL && echo True || (echo False & exit /b 1)