findstr

Findstr does not work with SET /P?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 07:58:41
I have a batch file with a portion shown below: rem @echo off cd C:\Program Files\CA\AllFusion Gen\GEN\test8.ief\c\ FINDSTR /C:"'V1600 OPER'" /C:"'V1714 OPER'" /C:"'V1801 OPER'" /C:"'V1901 OPER'" "MPOAD10C" The above batch file runs successfully with the above code. However, when I modified the script so that the user can enter two variables, as shown below (%path%=test8.ief,%file_name%=MPOAD10C) , it throws the following error: 'FINDSTR' is not recognized as an internal or external command,operable program or batch file. rem @echo off SET /P path=Enter name of IEF folder: echo. && echo. SET

Batch file to output last line of findstr

天大地大妈咪最大 提交于 2019-12-02 04:15:51
I am trying to find a list of machines in files in folders, and print out the last line of the output only. @echo off for /f %%a in (computers.txt) do findstr /xs "%%a" unhealthy.txt pause The computers.txt file has a list of 300 machines. I want that to output only the last line of each instance it finds. Right now the command displays and outputs all instances of the computer name, not just the tail end. I've tried to use "tail for Windows" but am getting errors as well. Current output: 2013\10-Oct\28\unhealthy.txt:WIN57505 2013\10-Oct\29\unhealthy.txt:WIN57505 2013\10-Oct\30\unhealthy.txt

How to match IP address by using 'findstr'? Or any other method of batch in windows

喜夏-厌秋 提交于 2019-12-01 22:47:38
As the title said, I want to match ip address with batch in windows, please tell me how I can do it? I see that " findstr " can match with regex like " [0-9] ", but how can "findstr" matches it appears one to three times ? Since findstr 's regex support is a bit ... dated, you usually can't use most regexes you find on the web. The following matches four runs of digits, separated by dots: ipconfig | findstr /r "[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" However, if you're only interested in addresses and not the subnet masks, you might want to use ipconfig | findstr /r "Address.*[0-9]

Grep for windows

好久不见. 提交于 2019-12-01 17:36:58
问题 Old.txt contains apple orange banana And New.txt contains apple orange banana grape lemon I can access new contents which are added to New.txt using grep command. grep -Fxvf Old.txt New.txt > difference.txt Now, difference.txt contains grape lemon In Windows, I have tried findstr /rvc:Old.txt New.txt > difference.txt to find the difference but it append contents of Old.txt too. How can I write equivalent command in Windows? 回答1: You can use DOS findstr with the following flags:- /v : Prints

Replace specific text in csv via commandline

。_饼干妹妹 提交于 2019-12-01 13:20:28
I have data in csv format that gets output from SQL Server . The data has some NULL and N.A. values written out which makes a column character type - it would otherwise have consisted of just integers. Is it possible via batch file statements to find and replace these values with number - say, -1 for NULL and -2 for N.A. . Here is how the data looks like now: Col A, Col B, Col C, Col D, Col E, Col F, Col G, Col H NULL, 13, 11, N.A., 4710, N.A., 1, 1 5, NULL, 13, 7070, N.A., 4920, N.A., 1 5, NULL, 12, 8680, N.A., 9130, N.A., 1 I would like to convert it to this: Col A, Col B, Col C, Col D, Col

Find text in file and set it as a variable. Batch file

眉间皱痕 提交于 2019-12-01 11:39:24
I try to find one line in whole text file. Next I need to set this line as a variable. When i try do this: set MY_VARIABLE=findstr /I "MY_TEXT" MY.FILE echo MY_VARIABLE the result of echo is "findstr /I "MY_TEXT" MY.FILE" i want to see result of "findstr /I "MY_TEXT" MY.FILE" not a command when i try do this first enter in cmd for /F "delims=" %%a in ('findstr /I "MY_TEXT" MY.FILE') do set "batToolDir=%%a" second enter in cmd echo "%batToolDir%" i see " the %%a variable is unsuspected " when i make a file SCRIPT.bat @echo off for /F "delims=" %%a in ('set MY_VARIABLE=findstr /I "MY_TEXT" MY

Replace specific text in csv via commandline

余生颓废 提交于 2019-12-01 10:11:46
问题 I have data in csv format that gets output from SQL Server . The data has some NULL and N.A. values written out which makes a column character type - it would otherwise have consisted of just integers. Is it possible via batch file statements to find and replace these values with number - say, -1 for NULL and -2 for N.A. . Here is how the data looks like now: Col A, Col B, Col C, Col D, Col E, Col F, Col G, Col H NULL, 13, 11, N.A., 4710, N.A., 1, 1 5, NULL, 13, 7070, N.A., 4920, N.A., 1 5,

【转】【bat】Bat 中特殊符号

烈酒焚心 提交于 2019-12-01 09:00:45
批处理、 Bat 中特殊符号的实际作用,Windows 批处理中特殊符号的作用: @ \\隐藏命令的回显。 ~ \\在for中表示使用增强的变量扩展; 在set中表示使用扩展环境变量指定位置的字符串; 在set/a中表示按位取反。 % \\使用两个%包含一个字符串表示引用环境变量。比如一个%time%可以扩展到当前的系统时间; 单个%紧跟0-9的一个数字表示引用命令行参数; 用于for中表示引用循环变量; 连续的两个%表示执行时脱为一个%。 ^ \\取消 转义字符 ,即将所有 转义字符 的转义作用关闭。比如要在屏幕显示一些特殊的字符,比如> >> | ^等时,就可以在其前面加一个^符号来显示这个^后面的字符了,^^就是显示一个^,^|就是显示一个|字符了; 在set/a中是按位异; 在findstr/r的[]中表示不匹配指定的字符集。 & \\命令连接字符。比如我要在一行文本上同时执行两个命令,就可以用&命令连接这两个命令; 在set/a中是按位与。 * \\代表任意个任意字符,就是我们通常所说的"通配符";比如想在c盘的根目录查找c盘根目录里所有的文本文件(.txt),那么就可以输入命令"dir c:\*.txt"; 在set/a中是乘法。比如"set/a x=4*2",得到的结果是8; 在findstr/r中表示将前一个字符多次匹配。 () \

Windows 'findstr' command: Exclude results containing particular string

二次信任 提交于 2019-12-01 00:25:38
问题 To the command findstr str1 *.* I want to add something that will exclude the results which contain the string str2 . In Linux the way of doing it is to add | grep -v str2 (to grep str1 * of course). Is there an equivalent flag to -v in Windows? 回答1: Is there an equivalent flag to -v in Windows? The equivalent to -v is /V . C:\Users\Todd>findstr /? Searches for strings in files. ... /V Prints only lines that do not contain a match. 回答2: use /V , for example: findstr "hello world" *.cpp |

Why does `findstr` with variable expansion in its search string return unexpected results when involved in a pipe?

青春壹個敷衍的年華 提交于 2019-11-30 15:18:14
While trying to provide a comprehensive answer to the question Why is FindStr returning not-found , I encountered strange behaviour of code that involves a pipe. This is some code based on the original question (to be executed in a batch-file ): rem // Set variable `vData` to literally contain `...;%main%\Programs\Go\Bin`: set "vData=...;%%main%%\Programs\Go\Bin" set "main=C:\Main" echo/%vData%| findstr /I /C:"%%main%%\\Programs\\Go\\Bin" This does not return a match, hence nothing is echoed and ErrorLevel becomes set to 1 . Though when I go through the parsing process step by step, I conclude