How do I (recursively) search all file contents in Windows 7? I am using the content:xxx command, in the Search settings box in Windows Explorer, to search xxx in this example. This does not work:
As an example of how this search is broken, I see an org.eclipse.wst.common.component file with text that I am searching for and Windows 7 is not returning it in the results. I assume it's only searching known text-based file types. How can I make it search all files? I need to find everything I am looking for.
P.S. If there is a DOS-based solution, I will also accept this. Maybe a batch file using dir /s /b and findstr could be constructed.
EDIT: Noted my need for a recursive search.
"user3245549" is right:
All of the above answers with "for loops" and nested bat files are mumbo jumbo. All you need is to just use "findstr" - example:
C:\temp> findstr /S /C:"/work" * | more <-- this will find the string "/work" in any file
or
C:\temp> findstr /S /C:"/work" "*.*" | more
or
C:\temp> findstr /S /C:"/work" * > results.txt
or
C:\temp> findstr /S /C:"/work" "*.*" > results.txt
NOTE: You can leave out the "double-quotes" around the asterisks - I just put those because the editor here on Stackoverflow was stripping out the asterisks on either side of the period.
NOTE ALSO: You still need the quotes around the "string text" for which you are searching, as far as I know.
If you are looking for a GUI-based solution where you don't have to remember the syntax, try out Notepad++. There is a Search menu which lets you search files in a directory (find in files), limit it to certain extensions (filter), and look in subfolders, and then you just click on the item in the list and it opens that file for edit.
Use the findstr command from a command prompt window.
/s give you a recursive search
/i ignores case
Here is my three file DOS solution, but I am still looking for a proper Windows 7 solution if anyone has one:
1. search.bat
#ECHO off
FOR /r %%a IN (*.*) DO CALL process.bat %%a
Searches all files recursively, and runs process.bat on each one.
2. process.bat
#ECHO Off
ECHO "%1" >> output.txt
TYPE "%1" | FINDSTR /i "search_string_here" >> output.txt
Prints out the name of each file, in quotes because some files will break the batch file code without, then finds the search string, search_string_here, and prints out the entire line that the search string is found in.
3. output.txt (sample output)
Contains the output, formatted as follows, searching search_string_here in my project_name Java project stored in D:\project_name\, displaying all files searched as well as results if there are some:
"D:\project_name\.classpath"
"D:\project_name\.project"
<name>search_string_here</name>
"D:\project_name\content_search_all_files.bat"
"D:\project_name\output.txt"
<name>search_string_here</name>
"D:\project_name\pom.xml"
...
Above you can see that search_string_here was found, full line being <name>search_string_here</name>, in D:\project_name\.project file... among other results.
Again, I am still looking for a proper Windows 7 solution if anyone has one.
Warning: "Line is too long" Errors; FINDSTR may be buggy:
Apparently, FINDSTR < grep, as if you didn't know. Here's an article that dives into the error in FINDSTR that are do not reproduce when the same input is used in a different file:
Obviously, “line is too long” is a catch-all message for a number of
different errors. FINDSTR has some issues. Some time ago, I said that
FINDSTR was marginally useful. After today, I’d say it’s even less
useful than I thought it was then.
- http://blog.mischel.com/2008/10/14/copying-large-files-on-windows/
This can be done through the command prompt, though the syntax is quite verbose
for /r %a in (\*.*) do find "search_text" %a
This now works in Windows 7 (extra dot removed)
If you're looking for a file or folder located in a common folder (such as Documents or Pictures), you can often find it fastest by using the Search box at the top of the folder window. For more information, see Use the Search box.Here.
If you're looking for a program, a website in your browser history, or a file that you've stored anywhere in your personal folder, you can use the Search box at the bottom of the Start menu. For more information, see Find a file or folder.Here.
If you're looking for several related files, such as all the files from a particular month, or all the documents that you have written, you can use the headings above the file list to filter, stack, or group your files. Organizing your files in one of these ways makes them easier to locate and select. For more information, see Use file list headings.Here
When you need to build a search with multiple filters, or when you're looking for files from several folders at once, create your search in the Search folder. When you are done, you can save the search criteria, and use it in the future to find the same set of files again with a single click. For more information, see Create an advanced search in the Search folder.Here
Related
I'm quite new to Linux. I'm using Linux Mint and I've just found a situation where I have a file which exists multiple times inside the tree/folders of a folder. I want to replace all occurrences of this file with a new version of it.
So instead of looking for that file once and again and replacing it with the new one, I wonder if there is any kind of search & replace command for files.
I've already searched for a similar question in stackoverflow, but I was only able to find commands to search & replace TEXT in files, not the file itself.
Can anyone please point me to the right direction?
Thank you.
you can always do it in parts, like:
Get a list of items matching your search.
Replace every match (using mv for example) with your file.
something like:
foreach dir ( `ls | egrep '^(i686\|amd64)\.'` )
mv yourfile $dir
end
This question already has answers here:
How to open a file in a list of files in Vim?
(11 answers)
Closed 7 years ago.
I'm analyzing a regression of thousands of test cases in linux. So I want to open many files(failed) in gvim at once.
I have a file as mention in below with 100+ lines specifying 100+ files in a directory. I want to open all these files in gvim(in single gvim).
./Linux2/Lint/case1/DIFF
./Linux2/Lint/case4/DIFF
./Linux2/Lint/case10/DIFF
./Linux2/range/case1/DIFF
./Linux2/operator/case7/DIFF
100+ lines like this.
Is there any way to open files in all these files in gvim with some navigation mechanism.
I know it is possible to use,
gvim file1 file2 .....
But it is not easy with 100+ files.
I need to do this in gvim, not in vim.
I just used find . -name DIFF | xargs vim and was able to navigate through all the files using :next and :prev and :buffers
Only ugly bit was when I hit about 1500 files I'd get two invocations of vim and would have to finish editing the first 1500 files before moving on to the next 1500 (Due to the way xargs works).
Another option is to use vims error file parsing. List all the files in an file with information about the line and error, open that file and run :cbuffer in that buffer (it will close the error file and move you to the first listed erro). :copen will open the list of errors as the Quickfix List. Then you can use the usual :cn and :cp to move between forward and backward in the quickfix list (and <CR> in the quickfix list will work too. Something like this should work out of the box for you.
:./Linux2/Lint/case1/DIFF:1: Not really an error
:./Linux2/Lint/case2/DIFF:1: Not really an error
:./Linux2/Lint/case3/DIFF:1: Not really an error
Now this can be improved since vims error parsing is flexible. You could remove the requirement for the leading : by using set errorformat=%f:%l:\ %m or just use a raw list of files using set errorformat=%f.
It sounds like you want to produce a command line argument from a file. You can do that with command substitution in bash.
gvim $(cat ListOfFiles.txt)
For something so simple that can easily be done with find replace in notepad, I can't see why it is so hard to do in a command line as it is just one step in the entire procedure that I would like to get down to a single run. The output from the first part lists the local path to all the websites in the webserver as the each local path c:/ etc. every site has the same 59 characters before the part that matters.
To make this a usable link, I need to then add a different string in the same position as the old one with the correct http://. etc. to the balance of the line to make it a working hyperlink.
The final step needs to convert any single "\’s" that are left to a "/". Normally there is only one
All of this can be done in notepad++ using find and replace but it takes 3 runs to achieve the end result the original text file is nothing special, no skipped lines, everyone is identical in layout.
The same 59 characters need to be chopped off (it could even be by Number and not by comparing the text, just shorten by 59 characters if that is easier. The replacement text string is always exactly the same that just gets appended to each line. And for the final touch of replacing every \ with a / to make it fully web-compatible there is only one occurrence on each line.
I have seen many find and replace batch-files that seem to be overkill for such a simple task.
Take each line, count fifty nine characters forward, chop off the 59 and add in the replacement text in its place.
Then change the only backslash in the line to a forward slash and it’s done
Does anyone know a simpler easier way to do this
This uses a helper batch file called repl.bat - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place repl.bat in the same folder as the batch file or in a folder that is on the path.
Just change http://www.domain.com/ to what you need to prefix the lines with.
type "file.txt" | repl "\\" "/" | repl "^.{59}" "http://www.domain.com/" >"newfile.txt"
The two \\ are intentional as it is a regular expression.
#ECHO OFF
SETLOCAL
(
FOR /f "delims=" %%a IN (Q21495128.txt) DO (
SET "line=%%a"
CALL SET "line=%%line:\=/%%"
CALL SET "line=replacement text%%line:~59%%"
FOR /f "tokens=1*delims==" %%x IN ('set line') DO ECHO %%y
)
)>newfile.txt
GOTO :EOF
where Q21495128.txt was my test source file worked for me.
I have .txt files (1 or more) in a directory that I want my batch file to read their filename, get 20 characters starting from the 4th and creating a new directory in the folder. Here is my code:
for /f %%i in ('dir /b *.TXT') do (
set filename1=%%i
set folder1=%filename1:~4,20%
mkdir %folder1%
)
When I run this program the 1st time, I get a syntax not correct error for the line 3rd line (set folder1=....) and no folder is created. I tried running it a 2nd time and 2 folders were created (one named "~4" and one named "20"). On the 3rd run, the folder was correctly created! If I close the command prompt and open it again, it also needs to run 3 times before it creates the folder.
I've also tried using "for /r . $$i in (*.TXT) with no luck. As I understand, the problem is that the line with "set folder1=..." does not get the proper filename. I've also tried using %%~i or %%~ni, I've tried outputing the filename (which seems to always get the correct string) to a text file and then reading from that file, again with no luck. I don't know what else to try. Is it because %%i stores the file itself and not a string with the filename?
A sample file is named "REG_18004247K_20120208_A.TXT" and I want a folder to be created with the name "18004247K_20120208_A".
I am not at all familiar with batch programming (I'm only working with batch files for like 2 weeks) and I'm guessing the problem might be something really simple. Any help would be appreciated.
Kyriacos
%%i does stores a string with a filename. It is actually the only "variable" that works as expected here.
The key problem is that you are using environment variable substitution (of filename1 and of folder1) inside a loop, hoping that it will be expanded in each iteration of the loop.
However, environment variables are expanded before execution of the whole loop begins.
So, upon the first batch execution, filename1 is not defined and you get
an error, folder1 is not set, and you probably also see a folder
called %folder1% created.
However, the scripts defines filename1 at this time, and the second execution gets further to define folder1 correctly (although line 4 was
already expanded using the incorrect value and fun happens).
The third execution
finally gets to see the right value of folder1; but this would obviously not
work for more than one file, as the loop logic is dysfunctional.
This older answer explains this problem with great other examples and special cases.
Your batch can be fixed by setlocal enabledelayedexpansion at the beginning of the script, initializing the variables to empty strings before the loop, and switching to the !...! syntax when expanding them: !filename1:~4,20!, and !folder1!.
setlocal enabledelayedexpansion
for /r %%i in (*) do (
set filename1=%%i
set folder1=!filename1:~4,20!
mkdir !folder1!
)
Because ... delayed expansion takes some time to store actual variable.
!...! rather than %...% echoes fast allocating variables to DOS.
Lets say we have two files as follows
File A.txt
Karthick is not so intelligent
He is not lazy
File B.txt
karthick is not so bad either
He is hard worker
so in the two files above, the commone words are "karthick is not so" & "He is" in each of the lines. Is there any way to print all such common lines with either grep command or some linux command?
You want to use the dwdiff utility :).
Example usage:
dwdiff "File A.txt" "File B.txt"
It might take a little while to get used to it's output, but check http://linux.die.net/man/1/dwdiff for more details on that.
There are also several visual diff applications out there, but I prefer using it on the command line.