Skip to main content

Questions tagged [findstr]

Use this for question about the DOS/cmd `findstr` command for searching for strings in files

Filter by
Sorted by
Tagged with
38 votes
4 answers
128k views

findstr DOS Command's multiple string argument

findstr /v "black" File1.txt Above DOS command will display content of 'File1.txt' which are not matching string "black". How to modify this command , if I need to filter words "black" and "white" ?...
Arun's user avatar
  • 545
36 votes
6 answers
69k views

What's the difference between the find and findstr commands in Windows?

In Windows, what are the differences between the find and findstr commands? Both seem to search for text in files: find C:\> find /? Searches for a text string in a file or files. FIND [/V] [/C]...
Prashant Bhate's user avatar
8 votes
3 answers
18k views

FINDSTR: Line is too long

Windows FINDSTR command is useful for sifting through large amounts of data; it filters out lines of text that match or don't match a specified pattern or string (like GNU/BSD grep). But it refuses ...
voices's user avatar
  • 2,741
7 votes
5 answers
64k views

How do I extract the IPv4 IP Address from the output of ipconfig

I'm attempting to have cmd copy only a specific set of character from a command output. I've been able to select the line that the phrase exists in but from there I am lost. Here is my command so far. ...
Samuel Pauk's user avatar
6 votes
4 answers
3k views

Using 'ping' and 'findstr' in a 'for' loop of batch file first throws error not an internal external command but it again shows output

This batch file @echo off set path=C:\Users\ssiyengar\Desktop\Pingtest\pinglist.csv set file=C:\Users\ssiyengar\Desktop\Pingtest\temp.txt set qosping=1 cls for /f "tokens=1-3 delims=," %%a ...
Srivatsan's user avatar
5 votes
1 answer
1k views

Vim: How do you use external grep on windows to search for quotation marks?

For some reason I can't for the life of me figure out how to pass single quotation marks to external tools when using vim. For example, I might want to call Vim's external grep to search for the text ...
Steve Vermeulen's user avatar
4 votes
1 answer
23k views

Use findstr to Search a Sub Directory for a String?

I can use the following to search for text files that contain the word "string" from the Windows Command Prompt: C:\>findstr /spin /c:"string" *.txt What if I want to search a sub-directory? The ...
GTS Joe's user avatar
  • 251
4 votes
1 answer
419 views

Is there a better way to mitigate this obscure color bug when piping to FINDSTR inside a parenthesized block of (.bat) code?

In the following .BAT file, test 2 demonstrates the color bug inside a parenthesized block of code, test 3 demonstrates the bug inside a FOR loop, and test 4 shows how the bug can be mitigated by ...
Dolores Stevens's user avatar
3 votes
2 answers
349 views

findstr /X keeps printing lines with no matches

I'm using nslookup and findstr in a simple batch script to check if a website is up. However findstr keeps printing lines which doesn't contain any matches. The command goes like this: nslookup ...
Mizuki's user avatar
  • 33
3 votes
3 answers
7k views

In windows, is there a way to count the amount of times a string appears in a file

I am currently trying to write a batch script and at this point, I need to find a string, "null", and determine how many times it is shown in the file. I'm downloading an API from a website every-...
user347636's user avatar
3 votes
0 answers
3k views

find string from multiple files and replace it without creating new file

I want to find string e.g. "date" from my files of a folder which contains multiple ".c" and ".h" files in it and replace it with "date 24-April-2018" using batch file. what should do? Please see ...
Meera's user avatar
  • 31
3 votes
2 answers
2k views

A powershell version of for /f (|findstr) for Unicode folders/files

Here is a small script I wrote that recursively scan a directory without some parent-subdirectories and extracts some attributes of the files within it. @echo off echo Path,Name,Extension,Size > ...
Roey Peretz's user avatar
2 votes
2 answers
8k views

Why does this 'findstr' command not function as expected?

I use the command-line program 'findstr' frequently as I write software. It helps me quickly locate all the files that contain a specific string in a set of subdirectories. It is a lot faster to use ...
CubicleSoft's user avatar
2 votes
2 answers
790 views

Search term in specific line in multiple files

I would like to search a text in multiple files (within a directory) at a certain line number. Example: I have ~100 Script Files in a directory (C:\Scripts) and I would like to scan all of these files ...
SteffPoint's user avatar
2 votes
2 answers
2k views

Most efficient command to search the first line of many files (windows)

I am new to the windows ecosystem. I have been tasked with writing a program that will search several 10's (maybe even 100's) of thousands of files for a particular string. The string that must be ...
tpdietz's user avatar
  • 121
2 votes
2 answers
9k views

Use Batch findstr for files with whitespaces

I'm trying to search for a string in a given file. This file can have whitespaces in its name and I'm having trouble with the Batch file. I can easily do this by console getting the correct results: ...
Alvaro's user avatar
  • 157
2 votes
1 answer
895 views

Windows make all files in folder that contain a line read-only

I have some files in a directory with the comment: // _READONLY_ I'd like to set all these files to read-only using a batch script. I've found this command to set read-only status: attrib +r I know ...
Raymo111's user avatar
  • 127
2 votes
1 answer
17k views

Batch File, dir | findstr within a for loop

Let me preface by admitting that I am a complete noob at batch files... and programming language in general. I am trying to write a batch file that allows the user to input a partial filename, and it ...
Gumbi's user avatar
  • 23
2 votes
1 answer
2k views

Get URL from HTML file using FindStr

I'd like to preface this by saying that I'm very new to the command prompt and I've been only using it for some WGET and YOUTUBE-DL, and that I'm on a Windows 8 PC. I'd like to get a bunch of links ...
user avatar
2 votes
2 answers
12k views

How do I extract the IPv4 IP Addresses from the output of ipconfig, and then filter it so that my output only includes a list of the IP addresses?

How do I extract the IPv4 IP Address from the output of ipconfig I read through this post and it was very helpful. I was just wondering if the is a way I can extract only the IP Addresses (xxx.xxx....
Hassan Daudzai's user avatar
2 votes
1 answer
2k views

Delete scheduled taskname containing space

I want to delete scheduled tasks that start with "Adobe Acrobat" eg "Adobe Acrobat 123","Adobe Acrobat 456","Adobe Acrobat 789" schtasks /Delete /TN Adobe* /F This command fails to find any tasks ...
eureka's user avatar
  • 143
2 votes
1 answer
56 views

Trying to capture same functionality in Windows cmd prompts as in a PowerShell list of commands using net localgroup

I work in an environment with a mix of older and newer Windows components on isolated networks. To try and make a certain task easier, I worked on a list of PowerShell commands to create a single text ...
Pokopokopoki's user avatar
2 votes
1 answer
1k views

grep -r (or -R) does not search inside subfolders

It has been some time since I don't use linux, using windows instead. In windows whenever I want to search for a string on files and files inside subfolders I do (for example for cs files) findstr /...
KansaiRobot's user avatar
2 votes
1 answer
873 views

How to go through a list of installed programs and take out any line with Microsoft-related strings?

This is on Windows 7 using command line and batch files. I was looking to examine my program list and uninstall a good amount of junk and update a good amount of outdated programs. I used a wmic ...
Zachary Johnson's user avatar
2 votes
2 answers
14k views

How to use FINDSTR to search in a specific line?

I have a file example.txt and a string "Hi" and the beginning of the 15th line. The required code for findstr should be: findstr /b /n "Hi" "example.txt" Is there something that can search for "Hi" ...
Ekagra Sinha's user avatar
2 votes
3 answers
200 views

Seemingly impossible to extract URL string in between two text delimiters from 100's of messy Google News Alert emails with batch

For years Google News Alerts has sent daily emails when certain words pop up in websites, tweets, etc. and these emails (in HTML and .txt format) have one unique quality: there is no easy way to pull ...
user1798732's user avatar
2 votes
1 answer
3k views

FINDSTR Multiple Search Strings [duplicate]

Looking for either word “ And ” or “ In ” with preceding and ending spaces, I can using following FINDSTR command: findstr /r /c:” And ” /c:” In “ textfile Is there a way to do similar search with ...
Sui's user avatar
  • 21
1 vote
2 answers
720 views

How to quickly determine which files contain only NULLs so they can be safely deleted (Windows)?

A friend has thousands of files that likely contain nothing but NULLs (ASCII 0). (If interested, see this Super User QA to learn why). The files range in size from 650 bytes to ~200MB (with the ...
End Antisemitic Hate's user avatar
1 vote
2 answers
1k views

how to extract a specific part of a string from character 7 to 17 and save it in new txt file (findstr, gnu32-sed or other tool)

How do I extract a specific part of a string from character 7 - 17 using regex via the command line? My string is ThisString and in the file data I have a lot of strings, but I need only ThisString ...
Tom's user avatar
  • 29
1 vote
1 answer
1k views

Pipe error in [Echo !file!|findstr]

with this script I read a Log file with filenames and search a string (with wildcards) in these list but the pipe for the findstr function doesn't work. setlocal enabledelayedexpansion for /f %%A in ...
THxy's user avatar
  • 23
1 vote
1 answer
6k views

Equivalent of a wildcard in find for batch?

I'm almost certain this is a duplicate but I was unable to find it after a lot of searching so forgive me. I'm looking for a way to have the equivalent of a wildcard in the find command. For ...
Mark Deven's user avatar
  • 1,660
1 vote
1 answer
3k views

How to exclude a folder from a string search

>>"results\txtmail.txt" findstr /i /p /s mail %userprofile%\*.txt Now, what if I want to exclude C:\Users\Username\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.IE5 from the ...
Daniel's user avatar
  • 283
1 vote
1 answer
2k views

Batch: Return the matching lines from pipe's output to the console with regex

I have the following domain checking bash script in Linux: #!/bin/bash TLD='.com' while read -r domain; do whois -H $domain$TLD | grep -oPaq '^.*(Creation Date|record created).*$' if [ $? -eq 0 ...
Lanti's user avatar
  • 139
1 vote
1 answer
2k views

CMD - Manually enter a value and check if it exists in a .txt with multiple lines > reply the result

I am trying to create a batch file which will check a given term against an existing text file with multiple lines (10000+ lines). More specifically, I have a list of domains that I want to blacklist, ...
Phantom's user avatar
  • 13
1 vote
1 answer
948 views

Findstr retuns an errorlevel code incorrect?

There is a file named myfile.txt contains the string "hpxu" Enter command prompt and I typing: findstr khry myfile.txt & echo %errorlevel% At first execution result is 0 at the second ...
adriansor's user avatar
1 vote
1 answer
948 views

How to get tab-initiated lines using Findstr /B [TAB] in Bat/CMD

There is an option that works in Unix & Linux: Like @jimmij answer command: grep -B2 '^\t' file. But is there an option using only bat/cmd with the Findstr command? Already tried.. Findstr /bl [...
Io-oI's user avatar
  • 8,297
1 vote
2 answers
1k views

Search txt-files for exact numbers with batchfile, findstr

I'm trying to search for exact numbers stored in text files using a batch file. The files are looking like this: 1, 2, 4, 11, 18, 19, 25, 35, 42, 66, 87, 89....... The problem is to avoid getting ...
Night Rider's user avatar
1 vote
2 answers
204 views

findstr 2 arguments and 2 events

I create a XML file from PRTG status monitor. in this XML file are values >4< for warning and >5< for error. With findstr and if errorlevel I can only check if one of the value is true or false,...
chriss chross's user avatar
1 vote
1 answer
385 views

search a UCS-2 file using batch

I have a file that is encoded in UCS-2 that is constantly being updated. I need to keep checking this file for a string of recurring text and then parsing the info. I originally tried using findstr ...
Allan Ballard's user avatar
1 vote
1 answer
289 views

Can't connect to a wireless network using cmd

Im trying to connect my phone to my PC via FTP and open the FTP with Windows Explorer using the cmd. Below are the codes: @echo off echo Setup connection to ftp 192.168.43.1 ipconfig | findstr /...
Xlam's user avatar
  • 157
1 vote
1 answer
3k views

Find a string at the beginning of all lines in a file and save to another file

I have tried quite a few options with no luck for this task. I would really like to do this as batch file but my attempts fail to get the desired result. I have tried a lot of different commands with ...
JAH's user avatar
  • 23
1 vote
1 answer
1k views

Windows XCOPY results from FIND command

Windows 7 CMD I can retrieve a list of files by the following command dir /b | find "TENDER_NUM 2". I'm trying to copy all the files that were returned by find into another folder. I've tried: for /...
BardsWork's user avatar
  • 141
1 vote
1 answer
2k views

What is the difference between regular and literal expressions in FINDSTR?

What is the difference between /R and /C? FINDSTR [options] [/F:file] [/C:string] [/G:file] [/D:DirList] [/A:color] [/OFF[LINE]] [string(s)] [pathname(s)] /C:string Use string as a literal ...
Dhiwakar Ravikumar's user avatar
1 vote
1 answer
9k views

Script to Find Certain words and delete those lines in a file

EDITED THE QUESTION as i am open to different type of solutions unlike just batch previously I am on Windows & some suggested SED etc. So i am OK with these 3rd party standalone exe's using ...
SuperUserMan's user avatar
1 vote
1 answer
583 views

Windows Find Regex - findstr LookBehind

I have this string: DisplayName REG_SZ Paquete de controladores de Windows - Intel Corporation (iaStorA) HDC (07/22/2015 14.5.2.1088) Which I have taken from: Reg Query HKLM\Software\...
aDoN's user avatar
  • 111
1 vote
0 answers
2k views

Find "mystring" in files and return only certain portion of matching lines

I have below command to list out every file in current directory and it's sub-directories containing "mystring" along with the line where search string match is found. @echo off setlocal findstr /s ...
Vicky Dev's user avatar
  • 472
1 vote
1 answer
2k views

Dir and Findstr commands taking a long time to complete in Batch File

dir %DRIVE_NAME%: /S /C /A-D /Q /T:C | findstr ".zip$ .doc$ .xls$ .xpt$ .cpt$ .cpo$ .xlsx$ .pdf$ .dat$ .txt$ .docx$ .csv$" >> file.info I am using above command to list all information in file, ...
user2405934's user avatar
1 vote
1 answer
299 views

Batch : extract some characters of a string

How can I extract alphanumeric characters only from a string? Example : b:lbalbqsd1287/;:!, gives blbalbqsd1287 Is it possible with findstr?
Basj's user avatar
  • 1,900
1 vote
0 answers
1k views

Find vs Findstr results

Per this answer I was attempting to use findstr to locate a string (a name) inside some HL7 log files in a directory. Findstr was getting 0 results, but Find returned plenty. I played around with ...
user avatar
0 votes
1 answer
3k views

How to correctly write regex to findstr for cmd?

I am trying to only print UUID in windows and running following command: wmic csproduct get uuid | findstr /R “[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}-[a-zA-Z0-9]{5}” Above command returns ...
Ishan Patel's user avatar